๋ฐ์ํ
import Foundation
func solution(_ targets:[[Int]]) -> Int {
var targets = targets
var e = 0
targets = targets.sorted { ($0[1], $0[0]) < ($1[1], $1[0]) }
var res = 0
for target in targets {
if target[0] >= e {
res += 1
e = target[1]
}
}
return res
}
์ด์ฐจ์๋ฐฐ์ด์ ์ ๋ ฌ์ sorted { ($0[1], $0[0]) < ($1[1], $1[0]) }
๊ฐ๊ตฌ๊ฐ์ผ๋ก ์์ง๋ง ํ๊ตฌ๊ฐ์ผ๋ก๋ ๋น๊ตํ ์ ์์๋ค.
๋ฐ์ํ
'๐ ์ฝํ > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ํ๋ก๊ทธ๋๋จธ์ค42862 ์ฒด์ก๋ณต (0) | 2023.05.13 |
---|---|
[Swift] ํ๋ก๊ทธ๋๋จธ์ค154539 ๋ค์ ์๋ ํฐ ์ ์ฐพ๊ธฐ (0) | 2023.05.13 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค92342 ์๊ถ๋ํ (0) | 2023.05.11 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค118667 ๋ ํ ํฉ ๊ฐ๊ฒ ๋ง๋ค๊ธฐ (0) | 2023.05.11 |
[Swift] ํ๋ก๊ทธ๋๋จธ์ค150369 ํ๋ฐฐ๋ฐฐ๋ฌ๊ณผ ์๊ฑฐํ๊ธฐ (0) | 2023.05.10 |