프로그래머스/Lv.1
프로그래머스 코딩테스트 연습 Lv.1 Swift
-
import Foundation func solution(_ s:String, _ skip:String, _ index:Int) -> String { let filtered = "abcdefghijklmnopqrstuvwxyz".filter { !skip.contains($0) }.map { $0 } let maps = filtered.enumerated().reduce(into: [:]) { dict, v in dict[v.element] = filtered[(v.offset+index) % filtered.count] } return s.map { String(maps[$0]!) }.joined() }
[Swift] 둘만의 암호import Foundation func solution(_ s:String, _ skip:String, _ index:Int) -> String { let filtered = "abcdefghijklmnopqrstuvwxyz".filter { !skip.contains($0) }.map { $0 } let maps = filtered.enumerated().reduce(into: [:]) { dict, v in dict[v.element] = filtered[(v.offset+index) % filtered.count] } return s.map { String(maps[$0]!) }.joined() }
2023.02.12 -
import Foundation func solution(_ a:Int, _ b:Int) -> Int64 { return Int64((min(a, b)...max(a, b)).reduce(0, +)) }
[Swift] 두 정수 사이의 합import Foundation func solution(_ a:Int, _ b:Int) -> Int64 { return Int64((min(a, b)...max(a, b)).reduce(0, +)) }
2023.02.12 -
import Foundation func solution(_ numbers:[Int]) -> [Int] { var set = Set() for i in 0..
[Swift] 두개 뽑아서 더하기import Foundation func solution(_ numbers:[Int]) -> [Int] { var set = Set() for i in 0..
2023.02.12 -
import Foundation func solution(_ a:[Int], _ b:[Int]) -> Int { return zip(a, b).map{ $0 * $1 }.reduce(0, +) }
[Swift] 내적import Foundation func solution(_ a:[Int], _ b:[Int]) -> Int { return zip(a, b).map{ $0 * $1 }.reduce(0, +) }
2023.02.12 -
import Foundation func solution(_ n:Int) -> Int { var result = n-1 for i in 2..
[Swift] 나머지가 1이 되는 수 찾기import Foundation func solution(_ n:Int) -> Int { var result = n-1 for i in 2..
2023.02.12 -
import Foundation func solution(_ arr:[Int], _ divisor:Int) -> [Int] { let result = arr.sorted().filter{ $0 % divisor == 0} return result.count == 0 ? [-1] : result }
[Swift] 나누어 떨어지는 숫자 배열import Foundation func solution(_ arr:[Int], _ divisor:Int) -> [Int] { let result = arr.sorted().filter{ $0 % divisor == 0} return result.count == 0 ? [-1] : result }
2023.02.12 -
import Foundation func solution(_ number:Int, _ limit:Int, _ power:Int) -> Int { var attack = [Int](repeating: 0, count: number+1) for i in 1...number { var c = i while c limit ? power : $0 } return attack.reduce(0, +) }
[Swift] 기사단원의 무기import Foundation func solution(_ number:Int, _ limit:Int, _ power:Int) -> Int { var attack = [Int](repeating: 0, count: number+1) for i in 1...number { var c = i while c limit ? power : $0 } return attack.reduce(0, +) }
2023.02.12 -
import Foundation func solution(_ k:Int, _ m:Int, _ score:[Int]) -> Int { var answer = 0 var score = score.sorted{$0 > $1} var start = m-1 while start < score.count { answer += m*score[start] start += m } return answer }
[Swift] 과일 장수import Foundation func solution(_ k:Int, _ m:Int, _ score:[Int]) -> Int { var answer = 0 var score = score.sorted{$0 > $1} var start = m-1 while start < score.count { answer += m*score[start] start += m } return answer }
2023.02.12