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
+ /**
2
+ * ๊ตฌ๊ฐ์ด ๊ฒน์น์ง ์๊ฒ ํ๊ธฐ ์ํด ์ต์ํ์ ๊ตฌ๊ฐ์ ์์ ์ผ ํ ๋, ๋ช ๊ฐ๋ฅผ ์์ ์ผ ํ๋์ง ๋ฐํํ๋ ํจ์
3
+ * @param {number[][] } intervals
4
+ * @return {number }
5
+ */
6
+ const eraseOverlapIntervals = function ( intervals ) {
7
+ intervals . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) ;
8
+
9
+ let count = 0 ;
10
+ let prevEnd = intervals [ 0 ] [ 1 ] ;
11
+
12
+ for ( let i = 1 ; i < intervals . length ; i ++ ) {
13
+ const [ start , end ] = intervals [ i ] ;
14
+
15
+ // ๋ฒ์๊ฐ ๊ฒน์น๋ ๊ฒฝ์ฐ
16
+ if ( prevEnd > start ) {
17
+ count ++ ;
18
+ prevEnd = Math . min ( prevEnd , end ) ; // end๊ฐ ํฐ ๊ฑธ ์ญ์ ํ๋ค ์น๊ธฐ
19
+ }
20
+ }
21
+
22
+ return count ;
23
+ } ;
24
+
25
+ // ์๊ฐ๋ณต์ก๋: O(n)
26
+ // ๊ณต๊ฐ๋ณต์ก๋: O(1)
You canโt perform that action at this time.
0 commit comments