문제 출처: https://leetcode.com/problems/n-repeated-element-in-size-2n-array/submissions/
func repeatedNTimes(_ nums: [Int]) -> Int {
var count = 0
var sorted = nums.sorted()
var left = sorted[count]
var right = sorted[count+1]
while left != right {
count += 1
left = sorted[count]
right = sorted[count+1]
}
return left
}
문제 출처: https://programmers.co.kr/learn/courses/30/lessons/42578
func solution(_ clothes:[[String]]) -> Int {
var set = Set<String>()
var temp = Int()
var resultArray = [Int]()
for i in 0..<clothes.count {
set.insert(clothes[i][1])
}
for i in set {
temp = clothes.filter { $0[1] == i }.count + 1
resultArray.append(temp)
}
let result = resultArray.reduce(1) { $0 * $1 } - 1
return result
}