프로그래머스/Lv.0
프로그래머스 코딩테스트 연습 Lv.0 Swift
-
import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 % num2 }
[Swift] 나머지 구하기import Foundation func solution(_ num1:Int, _ num2:Int) -> Int { return num1 % num2 }
2022.12.13 -
import Foundation func solution(_ balls:Int, _ share:Int) -> Int64 { var min = balls - share < share ? balls - share : share var answer: Int64 = 1 if min == 0 { return 1 } for i in 1...min { answer *= Int64(balls-min+i) answer /= Int64(i) } return answer }
[Swift] 구슬을 나누는 경우의 수import Foundation func solution(_ balls:Int, _ share:Int) -> Int64 { var min = balls - share < share ? balls - share : share var answer: Int64 = 1 if min == 0 { return 1 } for i in 1...min { answer *= Int64(balls-min+i) answer /= Int64(i) } return answer }
2022.12.13 -
import Foundation func solution(_ numbers:[Int], _ k:Int) -> Int { (k - 1) * 2 % numbers.count + 1 }
[Swift] 공던지기import Foundation func solution(_ numbers:[Int], _ k:Int) -> Int { (k - 1) * 2 % numbers.count + 1 }
2022.12.13 -
import Foundation func solution(_ lines:[[Int]]) -> Int { var wholeLine = Array(repeating: 0, count: 200) for line in lines { for idx in stride(from: line.first!, to: line.last!, by: 1) { wholeLine[idx] += 1 } } return wholeLine.filter { $0 >= 2 }.count }
[Swift] 겹치는 선분의 길이import Foundation func solution(_ lines:[[Int]]) -> Int { var wholeLine = Array(repeating: 0, count: 200) for line in lines { for idx in stride(from: line.first!, to: line.last!, by: 1) { wholeLine[idx] += 1 } } return wholeLine.filter { $0 >= 2 }.count }
2022.12.13 -
import Foundation func solution(_ hp:Int) -> Int { return (hp / 5) + ((hp % 5) / 3) + (hp % 3) }
[Swift] 개미 군단import Foundation func solution(_ hp:Int) -> Int { return (hp / 5) + ((hp % 5) / 3) + (hp % 3) }
2022.12.13 -
import Foundation func solution(_ angle:Int) -> Int { if angle == 180 { return 4 } else if angle > 90 { return 3 } else if angle == 90 { return 2 } else { return 1 } return 0 }
[Swift] 각도기import Foundation func solution(_ angle:Int) -> Int { if angle == 180 { return 4 } else if angle > 90 { return 3 } else if angle == 90 { return 2 } else { return 1 } return 0 }
2022.12.13 -
import Foundation func solution(_ array:[Int]) -> [Int] { [array.max()!, array.index(of: array.max()!)!] }
[Swift] 가장 큰 수 찾기import Foundation func solution(_ array:[Int]) -> [Int] { [array.max()!, array.index(of: array.max()!)!] }
2022.12.13 -
import Foundation func solution(_ rsp:String) -> String { rsp.map { $0 == "0" ? "5" : $0 == "2" ? "0" : "2" }.joined() }
[Swift] 가위 바위 보import Foundation func solution(_ rsp:String) -> String { rsp.map { $0 == "0" ? "5" : $0 == "2" ? "0" : "2" }.joined() }
2022.12.13