분류 전체보기
-
import Foundation func solution(_ num_list:[Int]) -> [Int] { let count = num_list.filter { $0 % 2 == 0 }.count return [count, num_list.count - count] }
[Swift] 편지import Foundation func solution(_ num_list:[Int]) -> [Int] { let count = num_list.filter { $0 % 2 == 0 }.count return [count, num_list.count - count] }
2023.02.08 -
import Foundation func solution(_ n:Int) -> Int { var result = 1 var i = 1 while result
[Swift] 팩토리얼import Foundation func solution(_ n:Int) -> Int { var result = 1 var i = 1 while result
2023.02.08 -
import Foundation func solution(_ my_string:String, _ letter:String) -> String { return my_string.filter{ String($0) != letter } }
[Swift] 특정 문자 제거하기import Foundation func solution(_ my_string:String, _ letter:String) -> String { return my_string.filter{ String($0) != letter } }
2023.02.08 -
import Foundation func solution(_ numlist:[Int], _ n:Int) -> [Int] { return numlist.sorted(by: { (abs($0 - n), -$0) < (abs($1 - n), -$1) }) }
[Swift] 특이한 정렬import Foundation func solution(_ numlist:[Int], _ n:Int) -> [Int] { return numlist.sorted(by: { (abs($0 - n), -$0) < (abs($1 - n), -$1) }) }
2023.02.08 -
import Foundation func solution(_ s:String) -> Int { var stack = [Int]() for str in s.components(separatedBy: " ") { if str == "Z" { stack.popLast() } else { stack.append(Int(str)!) } } return stack.reduce(0, +) }
[Swift] 컨트롤 제트import Foundation func solution(_ s:String) -> Int { var stack = [Int]() for str in s.components(separatedBy: " ") { if str == "Z" { stack.popLast() } else { stack.append(Int(str)!) } } return stack.reduce(0, +) }
2023.02.08 -
import Foundation func solution(_ keyinput:[String], _ board:[Int]) -> [Int] { let board = board.map { $0 / 2 } var x = 0 var y = 0 for input in keyinput { switch input { case "right": x += 1 if x > board[0] { x = board[0] } case "left": x -= 1 if abs(x) > board[0] { x = -board[0] } case "up": y += 1 if y > board[1] { y = board[1] } case "down": y -= 1 if abs(y) > board[1] { y = -board[1] } defa..
[Swift] 캐릭터의 좌표import Foundation func solution(_ keyinput:[String], _ board:[Int]) -> [Int] { let board = board.map { $0 / 2 } var x = 0 var y = 0 for input in keyinput { switch input { case "right": x += 1 if x > board[0] { x = board[0] } case "left": x -= 1 if abs(x) > board[0] { x = -board[0] } case "up": y += 1 if y > board[1] { y = board[1] } case "down": y -= 1 if abs(y) > board[1] { y = -board[1] } defa..
2023.02.08 -
import Foundation func solution(_ chicken:Int) -> Int { var result = 0 var coupon = chicken while coupon >= 10 { result += coupon / 10 coupon = coupon / 10 + coupon % 10 } return result }
[Swift] 치킨 쿠폰import Foundation func solution(_ chicken:Int) -> Int { var result = 0 var coupon = chicken while coupon >= 10 { result += coupon / 10 coupon = coupon / 10 + coupon % 10 } return result }
2023.02.08 -
import Foundation func solution(_ array:[Int]) -> Int { let result = Set(array).map { num in (num: num, count: array.filter { $0 == num }.count) }.sorted { $0.count > $1.count } return result.count > 1 && result[0].count == result[1].count ? -1 : result[0].num }
[Swift] 최빈값 구하기import Foundation func solution(_ array:[Int]) -> Int { let result = Set(array).map { num in (num: num, count: array.filter { $0 == num }.count) }.sorted { $0.count > $1.count } return result.count > 1 && result[0].count == result[1].count ? -1 : result[0].num }
2023.02.08