프로그래머스/Lv.1
프로그래머스 코딩테스트 연습 Lv.1 Swift
-
func solution(_ s:String) -> Bool { return (Int(s) != nil && (s.count == 4 || s.count == 6)) ? true : false }
[Swift] 문자열 다루기 기본func solution(_ s:String) -> Bool { return (Int(s) != nil && (s.count == 4 || s.count == 6)) ? true : false }
2023.02.14 -
import Foundation func solution(_ s:String) -> String { String(s.sorted(by: >)) }
[Swift] 문자열 내림차순으로 배치하기import Foundation func solution(_ s:String) -> String { String(s.sorted(by: >)) }
2023.02.14 -
import Foundation func solution(_ s:String) -> Bool { let string = s.lowercased() return string.components(separatedBy: "p").count == string.components(separatedBy: "y").count }
[Swift] 문자열 내 p와 y의 개수import Foundation func solution(_ s:String) -> Bool { let string = s.lowercased() return string.components(separatedBy: "p").count == string.components(separatedBy: "y").count }
2023.02.14 -
import Foundation func solution(_ strings:[String], _ n:Int) -> [String] { return strings.sorted { Array($0)[n] == Array($1)[n] ? $0 < $1 : Array($0)[n] < Array($1)[n] } }
[Swift] 문자열 내 마음대로 정렬하기import Foundation func solution(_ strings:[String], _ n:Int) -> [String] { return strings.sorted { Array($0)[n] == Array($1)[n] ? $0 < $1 : Array($0)[n] < Array($1)[n] } }
2023.02.14 -
import Foundation func solution(_ s:String) -> Int { var stack = [Character]() var count = 0 for c in s { if stack.isEmpty { count += 1 stack.append(c) } else { if stack.last! == c { stack.append(c) } else { stack.popLast() } } } return count }
[Swift] 문자열 나누기import Foundation func solution(_ s:String) -> Int { var stack = [Character]() var count = 0 for c in s { if stack.isEmpty { count += 1 stack.append(c) } else { if stack.last! == c { stack.append(c) } else { stack.popLast() } } } return count }
2023.02.14 -
import Foundation func solution(_ answers:[Int]) -> [Int] { let student = ( a : [1, 2, 3, 4, 5], b : [2, 1, 2, 3, 2, 4, 2, 5], c : [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] ) var answer = [1:0, 2:0, 3:0] for (i, v) in answers.enumerated() { if v == student.a[i % student.a.count] { answer[1]! += 1 } if v == student.b[i % student.b.count] { answer[2]! += 1 } if v == student.c[i % student.c.count] { answer[3]..
[Swift] 모의고사import Foundation func solution(_ answers:[Int]) -> [Int] { let student = ( a : [1, 2, 3, 4, 5], b : [2, 1, 2, 3, 2, 4, 2, 5], c : [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] ) var answer = [1:0, 2:0, 3:0] for (i, v) in answers.enumerated() { if v == student.a[i % student.a.count] { answer[1]! += 1 } if v == student.b[i % student.b.count] { answer[2]! += 1 } if v == student.c[i % student.c.count] { answer[3]..
2023.02.14 -
import Foundation // k 일 이전 : 제일 작은 수 // k 일 이후 : 제일 작은 수 보다 큰 수 func solution(_ k:Int, _ score:[Int]) -> [Int] { var answer: [Int] = [] var newScore: [Int] = [] for index in 0..) if newScore.count < k { answer.append(newScore.last!) } else { answer.append(newScore[k - 1]) } } return answer }
[Swift] 명예의 전당import Foundation // k 일 이전 : 제일 작은 수 // k 일 이후 : 제일 작은 수 보다 큰 수 func solution(_ k:Int, _ score:[Int]) -> [Int] { var answer: [Int] = [] var newScore: [Int] = [] for index in 0..) if newScore.count < k { answer.append(newScore.last!) } else { answer.append(newScore[k - 1]) } } return answer }
2023.02.12 -
import Foundation func solution(_ lottos:[Int], _ win_nums:[Int]) -> [Int] { let zeroCount = lottos.filter{ $0 == 0 }.count let winCount = win_nums.filter{ lottos.contains($0) }.count return [min(7 - winCount - zeroCount, 6), min(7 - winCount, 6)] lottos.sorted() }
[Swift] 로또의 최고순위와 최저순위import Foundation func solution(_ lottos:[Int], _ win_nums:[Int]) -> [Int] { let zeroCount = lottos.filter{ $0 == 0 }.count let winCount = win_nums.filter{ lottos.contains($0) }.count return [min(7 - winCount - zeroCount, 6), min(7 - winCount, 6)] lottos.sorted() }
2023.02.12