File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
non-overlapping-intervals Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
You canโt perform that action at this time.
0 commit comments