프로그래머스
-
import Foundation func solution(_ numbers:[Int]) -> Int { let arr = numbers.sorted(by: >) return arr[0] * arr[1] }
[Swift] 최댓값 만들기(1)import Foundation func solution(_ numbers:[Int]) -> Int { let arr = numbers.sorted(by: >) return arr[0] * arr[1] }
2023.02.07 -
import Foundation func solution(_ n:Int) -> Int { return (0...n).filter { $0 % 2 == 0 }.reduce(0, +) }
[Swift] 짝수의 합import Foundation func solution(_ n:Int) -> Int { return (0...n).filter { $0 % 2 == 0 }.reduce(0, +) }
2023.02.07 -
import Foundation func solution(_ n:Int) -> [Int] { return (0...n).filter{ $0 % 2 != 0 } }
[Swift] 짝수는 싫어요import Foundation func solution(_ n:Int) -> [Int] { return (0...n).filter{ $0 % 2 != 0 } }
2023.02.07 -
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(_ fees:[Int], _ records:[String]) -> [Int] { var result = [String : Int]() let records = records.map { $0.components(separatedBy: " ") }.forEach { let tmp = $0[0].components(separatedBy: ":") let time = Int(tmp[0])! * 60 + Int(tmp[1])! if result[$0[1]] == nil {result[$0[1]] = 0} if $0[2] == "IN" {result[$0[1]]! -= time} else {result[$0[1]]! += time} } result.forEa..
[Swift] 주차 요금 계산import Foundation func solution(_ fees:[Int], _ records:[String]) -> [Int] { var result = [String : Int]() let records = records.map { $0.components(separatedBy: " ") }.forEach { let tmp = $0[0].components(separatedBy: ":") let time = Int(tmp[0])! * 60 + Int(tmp[1])! if result[$0[1]] == nil {result[$0[1]] = 0} if $0[2] == "IN" {result[$0[1]]! -= time} else {result[$0[1]]! += time} } result.forEa..
2023.02.07 -
func solution(_ numbers:[Int], _ target:Int) -> Int { var count = 0 func DFS(index: Int, sum: Int) { if index == (numbers.count - 1) && sum == target { // 마지막 인덱스까지 모두 계산한 값이 target과 같다면 count += 1 // count를 +1해주고 return // 더 이상 계산할 값이 없으므로(자식노드가 없으므로) return 해준다 } guard index + 1 < numbers.count else { return } DFS(index: index+1, sum: sum + numbers[index + 1]) // +자식 노드 실행 DFS(index: index+1, ..
[Swift] 타겟넘버func solution(_ numbers:[Int], _ target:Int) -> Int { var count = 0 func DFS(index: Int, sum: Int) { if index == (numbers.count - 1) && sum == target { // 마지막 인덱스까지 모두 계산한 값이 target과 같다면 count += 1 // count를 +1해주고 return // 더 이상 계산할 값이 없으므로(자식노드가 없으므로) return 해준다 } guard index + 1 < numbers.count else { return } DFS(index: index+1, sum: sum + numbers[index + 1]) // +자식 노드 실행 DFS(index: index+1, ..
2023.02.07