Skip to content

Commit 04b00a3

Browse files
committed
solve
1 parent 450f2ca commit 04b00a3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
/// ๊ตฌ๊ฐ„์„ ๋‹ค๋ฃจ๋Š”๋ฐ, ๊ฒน์น˜์ง€ ์•Š๊ฒŒ ์ตœ๋Œ€/์ตœ์†Œ๋กœ ๋ฝ‘๋Š” ๋ฌธ์ œ -> ๋์  ๊ธฐ์ค€ ์ •๋ ฌ + ๊ทธ๋ฆฌ๋””
3+
/// ๊ฐ€์žฅ ๋นจ๋ฆฌ ๋๋‚˜๋Š” ๊ฒƒ๋“ค์„ ์„ ํƒํ•ด์•ผ ์ตœ๋Œ€ํ•œ ๋งŽ์ด ์„ ํƒํ•  ์ˆ˜ ์žˆ์Œ
4+
/// ๋์  ๊ธฐ์ค€ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ nlogn
5+
/// ์ˆœ์ฐจ์ ์œผ๋กœ ๋Œ๋ฉด์„œ ๊ฒน์น˜๋ฉด ์ œ๊ฑฐ(์•ž ๊ฒƒ๋“ค๋ณด๋‹ค ๋์ ์ด ๋” ๋’ค๋ผ์„œ, ์‹œ์ž‘๋งŒ ํ™•์ธํ•˜๋ฉด ๋จ)
6+
/// O(nlogn) time / O(n) space
7+
func eraseOverlapIntervals(_ intervals: [[Int]]) -> Int {
8+
let intervals = intervals.sorted { $0[1] < $1[1] }
9+
var end = intervals[0][1]
10+
var removal = 0
11+
12+
for i in 1..<intervals.count {
13+
let isOverlapping = intervals[i][0] < end
14+
if isOverlapping {
15+
removal += 1
16+
} else {
17+
end = intervals[i][1]
18+
}
19+
}
20+
21+
return removal
22+
}
23+
}

0 commit comments

Comments
ย (0)