분류 전체보기
-
import Foundation func solution(_ s:String) -> [Int] { var s = s var count = 0 var zeroCount = 0 while s != "1" { count += 1 zeroCount += s.components(separatedBy: "1").joined().count s = String(s.components(separatedBy: "0").joined().count, radix: 2) } return [count, zeroCount] }
[Swift] 이진 변환 반복하기import Foundation func solution(_ s:String) -> [Int] { var s = s var count = 0 var zeroCount = 0 while s != "1" { count += 1 zeroCount += s.components(separatedBy: "1").joined().count s = String(s.components(separatedBy: "0").joined().count, radix: 2) } return [count, zeroCount] }
2023.02.05 -
import Foundation func solution(_ clothes:[[String]]) -> Int { let count = Set(clothes.compactMap({ $0.last })).map { type in return clothes.filter { $0.last == type }.count + 1 } return count.reduce(1) { $0 * $1 } - 1 }
[Swift] 위장import Foundation func solution(_ clothes:[[String]]) -> Int { let count = Set(clothes.compactMap({ $0.last })).map { type in return clothes.filter { $0.last == type }.count + 1 } return count.reduce(1) { $0 * $1 } - 1 }
2023.02.04 -
import Foundation func solution(_ s:String) -> Bool { var left = 0 var right = 0 for c in s { switch c { case "(" : left += 1 case ")" : right += 1 default: continue } if right > left { return false } } return left == right ? true :false }
[Swift] 올바른 괄호import Foundation func solution(_ s:String) -> Bool { var left = 0 var right = 0 for c in s { switch c { case "(" : left += 1 case ")" : right += 1 default: continue } if right > left { return false } } return left == right ? true :false }
2023.02.04 -
import Foundation func solution(_ n:Int, _ a:Int, _ b:Int) -> Int { var n = n var a = a var b = b var answer = 0 repeat { a = (a + 1) / 2 b = (b + 1) / 2 answer += 1 } while a != b return answer }
[Swift] 예상 대진표import Foundation func solution(_ n:Int, _ a:Int, _ b:Int) -> Int { var n = n var a = a var b = b var answer = 0 repeat { a = (a + 1) / 2 b = (b + 1) / 2 answer += 1 } while a != b return answer }
2023.02.04 -
func solution(_ n:Int, _ words:[String]) -> [Int] { for i in 1..
[Swift] 영어 끝말잇기func solution(_ n:Int, _ words:[String]) -> [Int] { for i in 1..
2023.02.04 -
func solution(_ n:Int) -> Int { if n < 3 { return n } var f0 = 1 var f1 = 2 var f2 = 0 for _ in 3...n { f2 = (f0 + f1) % 1234567 f0 = f1 f1 = f2 } return f2 }
[Swift] 멀리 뛰기func solution(_ n:Int) -> Int { if n < 3 { return n } var f0 = 1 var f1 = 2 var f2 = 0 for _ in 3...n { f2 = (f0 + f1) % 1234567 f0 = f1 f1 = f2 } return f2 }
2023.02.04 -
import Foundation func solution(_ n:Int) -> Int { var answer : Int = n + 1 while true { if n.nonzeroBitCount == answer.nonzeroBitCount { break; } answer += 1 } return answer }
[Swift] 다음 큰 숫자import Foundation func solution(_ n:Int) -> Int { var answer : Int = n + 1 while true { if n.nonzeroBitCount == answer.nonzeroBitCount { break; } answer += 1 } return answer }
2023.02.04 -
import Foundation func solution(_ str1:String, _ str2:String) -> Int { let alphabet = "abcdefghijklmnopqrstuvwxyz" let lowerStr1 = str1.lowercased().map { $0 } let lowerStr2 = str2.lowercased().map { $0 } var set1 = [String]() var set2 = [String]() var union = [String]() var intersection = [String]() for i in 0..
[Swift] 뉴스 클러스터링import Foundation func solution(_ str1:String, _ str2:String) -> Int { let alphabet = "abcdefghijklmnopqrstuvwxyz" let lowerStr1 = str1.lowercased().map { $0 } let lowerStr2 = str2.lowercased().map { $0 } var set1 = [String]() var set2 = [String]() var union = [String]() var intersection = [String]() for i in 0..
2023.02.04