func solution(_ n:Int, _ lost:[Int], _ reserve:[Int]) -> Int {
var set : Set<Int> = Set(1...n)
var tmpSet = set
var lost = Set(lost)
var reuslt = n
var tmpLost = lost
var reserve = Set(reserve)
var tmpReserve = reserve
reserve.subtract(lost)
tmpLost.subtract(tmpReserve)
print("자기자신은 제외:\(tmpLost)")
print(reserve)
print(tmpLost)
var addedMinus = Array<Int>()
var addedPlus = Array<Int>()
var helper : [[Int]] = Array(repeating: [], count: reserve.count)
for (index,number) in reserve.sorted().enumerated(){
if number > 1 {
helper[index].append(number - 1)
}
if number < tmpSet.max()! {
helper[index].append(number + 1)
}
}
var arrayLost = Array(tmpLost).sorted()
for (i,number) in helper.enumerated() {
for (k,a) in arrayLost.enumerated(){
if number.contains(a){
//print("a가지고있다:\(a)")
arrayLost.remove(at: k)
break
}
}
}
//print(arrayLost.count)
return reuslt - arrayLost.count
}
.
다른 분 것 :
:https://programmers.co.kr/learn/courses/30/lessons/42862/solution_groups?language=swift
결론:
set은 inline주의, 순서없는거 주의.