프로그래머스
-
import Foundation func solution(_ absolutes:[Int], _ signs:[Bool]) -> Int { return (0..
[Swift] 음양 더하기import Foundation func solution(_ absolutes:[Int], _ signs:[Bool]) -> Int { return (0..
2023.02.15 -
import Foundation func solution(_ babbling:[String]) -> Int { var count: Int = 0 for element in babbling { var str = String(element) str = str.replacingOccurrences(of: "aya", with: "1") str = str.replacingOccurrences(of: "ye", with: "2") str = str.replacingOccurrences(of: "woo", with: "3") str = str.replacingOccurrences(of: "ma", with: "4") if Int(str) != nil && !str.contains("11") && !str.conta..
[Swift] 옹알이 (2)import Foundation func solution(_ babbling:[String]) -> Int { var count: Int = 0 for element in babbling { var str = String(element) str = str.replacingOccurrences(of: "aya", with: "1") str = str.replacingOccurrences(of: "ye", with: "2") str = str.replacingOccurrences(of: "woo", with: "3") str = str.replacingOccurrences(of: "ma", with: "4") if Int(str) != nil && !str.contains("11") && !str.conta..
2023.02.15 -
import Foundation func solution(_ d:[Int], _ budget:Int) -> Int { var budget = budget return d.sorted().filter { budget -= $0 return budget >= 0 }.count }
[Swift] 예산import Foundation func solution(_ d:[Int], _ budget:Int) -> Int { var budget = budget return d.sorted().filter { budget -= $0 return budget >= 0 }.count }
2023.02.15 -
import Foundation func solution(_ numbers: [Int]) -> Int { return (0...9).filter { !numbers.contains($0) }.reduce(0, +) }
[Swift] 없는 숫자 더하기import Foundation func solution(_ numbers: [Int]) -> Int { return (0...9).filter { !numbers.contains($0) }.reduce(0, +) }
2023.02.15 -
import Foundation func solution(_ n:Int) -> Int { n == 0 ? 0 : (1...n).filter{ n % $0 == 0 }.reduce(0, +) }
[Swift] 약수의 합import Foundation func solution(_ n:Int) -> Int { n == 0 ? 0 : (1...n).filter{ n % $0 == 0 }.reduce(0, +) }
2023.02.15 -
import Foundation func solution(_ left:Int, _ right:Int) -> Int { return (left...right).map{ number in (1...number).filter { number % $0 == 0 }.count % 2 == 0 ? number : -number }.reduce(0, +) }
[Swift] 약수의 개수와 덧셈import Foundation func solution(_ left:Int, _ right:Int) -> Int { return (left...right).map{ number in (1...number).filter { number % $0 == 0 }.count % 2 == 0 ? number : -number }.reduce(0, +) }
2023.02.15 -
import Foundation func solution(_ N:Int, _ stages:[Int]) -> [Int] { var countArray = Array.init(repeating: 0, count: N) // 각 스테이지 당 같혀 있는 사람들의 수 var probabilityArray = Array.init(repeating: (Int(0), Double(0.0)), count: N) // 스테이지, 실패율 var total = stages.count // 각 스테이지를 도전한 사람 for element in stages { guard element != N+1 else { // 모두 통과 했다면 배열에 넣지 않음 continue } countArray[element-1] += 1 } for ..
[Swift] 실패율import Foundation func solution(_ N:Int, _ stages:[Int]) -> [Int] { var countArray = Array.init(repeating: 0, count: N) // 각 스테이지 당 같혀 있는 사람들의 수 var probabilityArray = Array.init(repeating: (Int(0), Double(0.0)), count: N) // 스테이지, 실패율 var total = stages.count // 각 스테이지를 도전한 사람 for element in stages { guard element != N+1 else { // 모두 통과 했다면 배열에 넣지 않음 continue } countArray[element-1] += 1 } for ..
2023.02.15 -
import Foundation func solution(_ new_id:String) -> String { var result = new_id.lowercased().components(separatedBy: ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "]", "{", "}", ":", "?", ",", "", "/"]).joined().components(separatedBy: ".").filter { $0 != "" }.joined(separator: ".").trimmingCharacters(in: ["."]) if result.isEmpty { result = "a" } if 15
[Swift] 신규 아이디 추천import Foundation func solution(_ new_id:String) -> String { var result = new_id.lowercased().components(separatedBy: ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "]", "{", "}", ":", "?", ",", "", "/"]).joined().components(separatedBy: ".").filter { $0 != "" }.joined(separator: ".").trimmingCharacters(in: ["."]) if result.isEmpty { result = "a" } if 15
2023.02.15