๋ฐ์ํ
import Foundation
func solution(_ n:Int, _ lost:[Int], _ reserve:[Int]) -> Int {
var lost = lost.sorted(by:<)
var reserve = reserve.sorted(by:<)
while reserve.count > 0 {
let pop = reserve.removeLast()
if lost.contains(pop) {
lost = lost.filter { $0 != pop }
continue
}
if lost.contains(pop+1), !reserve.contains(pop+1) {
lost = lost.filter { $0 != pop+1 }
continue
}
if lost.contains(pop-1), !reserve.contains(pop-1) {
lost = lost.filter { $0 != pop-1 }
continue
}
}
return n-lost.count
}
ํ๋ ํ ์คํธ์ผ์ด์ค๊ฐ ์ ๋ ฌ์ด ์๋์ด์๋ค
๋ฌธ์ ์กฐ๊ฑด ๊ผผ๊ผผํ ์์ฝ์ด์ ์๊ฐ์ด ์ข ๊ฑธ๋ ธ๋ค. ๊ผผ๊ผผํ ์ฝ์
๋ฐ์ํ
'๐ ์ฝํ > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ํ๋ก๊ทธ๋๋จธ์ค60061 ๊ธฐ๋ฅ๊ณผ ๋ณด ์ค์น (1) | 2023.05.13 |
---|---|
[Swift] ํ๋ก๊ทธ๋๋จธ์ค12911 ๋ค์ ํฐ ์ซ์ (0) | 2023.05.13 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค154539 ๋ค์ ์๋ ํฐ ์ ์ฐพ๊ธฐ (0) | 2023.05.13 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค181188 ์๊ฒฉ์์คํ (0) | 2023.05.12 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค92342 ์๊ถ๋ํ (0) | 2023.05.11 |