We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 12b0db2 commit b86f31eCopy full SHA for b86f31e
1 file changed
โnon-overlapping-intervals/yyyyyyyyyKim.pyโ
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
3
+
4
+ # ๊ทธ๋ฆฌ๋
5
+ # ์๊ฐ๋ณต์ก๋ O(n log n), ๊ณต๊ฐ๋ณต์ก๋ O(1)
6
7
+ # ์์์ ๊ธฐ์ค ์ ๋ ฌ
8
+ intervals.sort()
9
+ answer = 0 # ์ ๊ฑฐํ ๊ฐ์
10
+ curr_end = intervals[0][1] # ์ฒซ ๊ตฌ๊ฐ ๋๋๋ ์ง์ ์ด๊ธฐํ
11
12
+ for i in range(1,len(intervals)):
13
+ start, end = intervals[i]
14
15
+ # ๊ฒน์น๋ ๊ฒฝ์ฐ(์ ๊ฑฐ)
16
+ if start < curr_end:
17
+ # ํ์ฌ ๊ตฌ๊ฐ ์ ๊ฑฐ
18
+ answer += 1
19
+ # ๋ ์์ ์ง์ ๋จ๊ธฐ๊ธฐ(๊ฒน์น๋ ๋ถ๋ถ์ ์ค์ด๊ธฐ์ํด)
20
+ curr_end = min(curr_end, end)
21
22
+ # ์๊ฒน์น๋ ๊ฒฝ์ฐ(ํ์ฌ ๊ตฌ๊ฐ์ ๋ค์ ๊ธฐ์ค์ผ๋ก ํ์)
23
+ else:
24
+ curr_end = end
25
26
+ return answer
0 commit comments