프로그래머스/Lv.0
프로그래머스 코딩테스트 연습 Lv.0 Swift
-
import Foundation func solution(_ emergency:[Int]) -> [Int] { emergency.map { emergency.sorted(by: >).firstIndex(of: $0)! + 1 } }
[Swift] 진료 순서 정하기import Foundation func solution(_ emergency:[Int]) -> [Int] { emergency.map { emergency.sorted(by: >).firstIndex(of: $0)! + 1 } }
2023.02.07 -
import Foundation func solution(_ dots:[[Int]]) -> Int { let arrX = dots.map { $0[0] } let arrY = dots.map { $0[1] } let length = arrX.max()! - arrX.min()! let height = arrY.max()! - arrY.min()! return abs(length * height) }
[Swift] 직각삼각형 넓이 구하기import Foundation func solution(_ dots:[[Int]]) -> Int { let arrX = dots.map { $0[0] } let arrY = dots.map { $0[1] } let length = arrX.max()! - arrX.min()! let height = arrY.max()! - arrY.min()! return abs(length * height) }
2023.02.07 -
import Foundation let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! } (1...n.first!).forEach { print(String(repeating: "*", count: $0)) }
[Swift] 직각삼각형 출력하기import Foundation let n = readLine()!.components(separatedBy: [" "]).map { Int($0)! } (1...n.first!).forEach { print(String(repeating: "*", count: $0)) }
2023.02.07 -
import Foundation func solution(_ array:[Int]) -> Int { return array.sorted()[array.count/2] }
[Swift] 중앙값 구하기import Foundation func solution(_ array:[Int]) -> Int { return array.sorted()[array.count/2] }
2023.01.23 -
import Foundation func solution(_ array:[Int], _ n:Int) -> Int { return array.filter { $0 == n }.count }
[Swift] 중복된 숫자 개수import Foundation func solution(_ array:[Int], _ n:Int) -> Int { return array.filter { $0 == n }.count }
2023.01.05 -
import Foundation func solution(_ my_string:String) -> String { var result = "" my_string.forEach { if !result.contains($0) { result += String($0) } } return result }
[Swift] 중복된 문자 제거import Foundation func solution(_ my_string:String) -> String { var result = "" my_string.forEach { if !result.contains($0) { result += String($0) } } return result }
2023.01.05 -
import Foundation func solution(_ box:[Int], _ n:Int) -> Int { box.map { $0 / n }.reduce(1, *) }
[Swift] 주사위의 개수import Foundation func solution(_ box:[Int], _ n:Int) -> Int { box.map { $0 / n }.reduce(1, *) }
2023.01.05 -
import Foundation func solution(_ M:Int, _ N:Int) -> Int { return M * N - 1 }
[Swift] 종이 자르기import Foundation func solution(_ M:Int, _ N:Int) -> Int { return M * N - 1 }
2023.01.05