File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 184
184
412|[ Fizz Buzz] ( ./0412-fizz-buzz.js ) |Easy|
185
185
414|[ Third Maximum Number] ( ./0414-third-maximum-number.js ) |Easy|
186
186
419|[ Battleships in a Board] ( ./0419-battleships-in-a-board.js ) |Medium|
187
+ 435|[ Non-overlapping Intervals] ( ./0435-non-overlapping-intervals.js ) |Medium|
187
188
442|[ Find All Duplicates in an Array] ( ./0442-find-all-duplicates-in-an-array.js ) |Medium|
188
189
443|[ String Compression] ( ./0443-string-compression.js ) |Medium|
189
190
448|[ Find All Numbers Disappeared in an Array] ( ./0448-find-all-numbers-disappeared-in-an-array.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 435. Non-overlapping Intervals
3
+ * https://leetcode.com/problems/non-overlapping-intervals/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of intervals intervals where intervals[i] = [starti, endi], return the
7
+ * minimum number of intervals you need to remove to make the rest of the intervals
8
+ * non-overlapping.
9
+ *
10
+ * Note that intervals which only touch at a point are non-overlapping. For example,
11
+ * [1, 2] and [2, 3] are non-overlapping.
12
+ */
13
+
14
+ /**
15
+ * @param {number[][] } intervals
16
+ * @return {number }
17
+ */
18
+ var eraseOverlapIntervals = function ( intervals ) {
19
+ let count = 0 ;
20
+
21
+ intervals . sort ( ( a , b ) => a [ 1 ] - b [ 1 ] ) ;
22
+ let prevEnd = intervals [ 0 ] [ 1 ] ;
23
+
24
+ for ( let i = 1 ; i < intervals . length ; i ++ ) {
25
+ const [ start , end ] = intervals [ i ] ;
26
+ if ( prevEnd > start ) count ++ ;
27
+ else prevEnd = end ;
28
+ }
29
+
30
+ return count ;
31
+ } ;
You can’t perform that action at this time.
0 commit comments