분류 전체보기
-
import Foundation func solution(_ food:[Int]) -> String { let myString = food.enumerated().map { String(repeating: String($0.offset), count: ($0.element % 2 == 0 ? $0.element : $0.element - 1) / 2) }.joined() myString return "\(myString)0\(String(myString.reversed()))" }
[Swift] 푸드 파이트 대회import Foundation func solution(_ food:[Int]) -> String { let myString = food.enumerated().map { String(repeating: String($0.offset), count: ($0.element % 2 == 0 ? $0.element : $0.element - 1) / 2) }.joined() myString return "\(myString)0\(String(myString.reversed()))" }
2023.02.16 -
import Foundation func distance(_ hand: (Int, Int), _ keyPad: (Int, Int)) -> Int { return abs(hand.0 - keyPad.0) + abs(hand.1 - keyPad.1) } func solution(_ numbers:[Int], _ hand:String) -> String { let hand = hand == "right" ? "R" : "L" let keyPad = [ 1 : (0,0), 2 : (0,1), 3 : (0,2), 4 : (1,0), 5 : (1,1), 6 : (1,2), 7 : (2,0), 8 : (2,1), 9 : (2,2), 11 : (3,0), 0 : (3,1), 12: (3,2) ] var answer =..
[Swift] 키패드 누르기import Foundation func distance(_ hand: (Int, Int), _ keyPad: (Int, Int)) -> Int { return abs(hand.0 - keyPad.0) + abs(hand.1 - keyPad.1) } func solution(_ numbers:[Int], _ hand:String) -> String { let hand = hand == "right" ? "R" : "L" let keyPad = [ 1 : (0,0), 2 : (0,1), 3 : (0,2), 4 : (1,0), 5 : (1,1), 6 : (1,2), 7 : (2,0), 8 : (2,1), 9 : (2,2), 11 : (3,0), 0 : (3,1), 12: (3,2) ] var answer =..
2023.02.16 -
import Foundation func solution(_ board:[[Int]], _ moves:[Int]) -> Int { var copyBoard = board var basket = [Int]() var count = 0 for col in moves { for row in 0..
[Swift] 크레인 인형 뽑기import Foundation func solution(_ board:[[Int]], _ moves:[Int]) -> Int { var copyBoard = board var basket = [Int]() var count = 0 for col in moves { for row in 0..
2023.02.16 -
import Foundation func solution(_ t:String, _ p:String) -> Int { var index = 0 var result = [String]() var t = Array(t).map { String($0)} while index + p.count
[Swift] 크기가 작은 부분 문자열import Foundation func solution(_ t:String, _ p:String) -> Int { var index = 0 var result = [String]() var t = Array(t).map { String($0)} while index + p.count
2023.02.16 -
import Foundation func solution(_ num:Int) -> Int { var number = num if number == 1 { return 0 } for i in 1..
[Swift] 콜라츠 추측import Foundation func solution(_ num:Int) -> Int { var number = num if number == 1 { return 0 } for i in 1..
2023.02.16 -
import Foundation func solution(_ a:Int, _ b:Int, _ n:Int) -> Int { return (n > b ? n - b : 0) / (a - b) * b }
[Swift] 콜라 문제import Foundation func solution(_ a:Int, _ b:Int, _ n:Int) -> Int { return (n > b ? n - b : 0) / (a - b) * b }
2023.02.16 -
import Foundation func solution(_ sizes:[[Int]]) -> Int { let sort_sizes = sizes.map{$0.sorted()} return sort_sizes.map{$0[0]}.max()! * sort_sizes.map{$0[1]}.max()! }
[Swift] 최소 직사각형import Foundation func solution(_ sizes:[[Int]]) -> Int { let sort_sizes = sizes.map{$0.sorted()} return sort_sizes.map{$0[0]}.max()! * sort_sizes.map{$0[1]}.max()! }
2023.02.16 -
import Foundation func gcd(_ n:Int, _ m:Int) -> Int { if n == 0 { return m } else { return gcd(m % n, n) } } func lcm(_ n:Int, _ m:Int) -> Int { return n * m / gcd(n, m) } func solution(_ n:Int, _ m:Int) -> [Int] { return [gcd(min(n, m),max(n, m)), lcm(min(n, m),max(n, m))] }
[Swift] 최대공약수와 최소공배수import Foundation func gcd(_ n:Int, _ m:Int) -> Int { if n == 0 { return m } else { return gcd(m % n, n) } } func lcm(_ n:Int, _ m:Int) -> Int { return n * m / gcd(n, m) } func solution(_ n:Int, _ m:Int) -> [Int] { return [gcd(min(n, m),max(n, m)), lcm(min(n, m),max(n, m))] }
2023.02.16