File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
solution/0400-0499/0435.Non-overlapping Intervals Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,26 @@ class Solution {
103
103
}
104
104
```
105
105
106
+ ### ** TypeScript**
107
+
108
+ ``` ts
109
+ function eraseOverlapIntervals(intervals : number [][]): number {
110
+ let n = intervals .length ;
111
+ if (n == 0 ) return 0 ;
112
+ intervals .sort ((a , b ) => a [1 ] - b [1 ]);
113
+ let end = intervals [0 ][1 ], ans = 0 ;
114
+ for (let i = 1 ; i < n ; ++ i ) {
115
+ let cur = intervals [i ];
116
+ if (end > cur [0 ]) {
117
+ ans ++ ;
118
+ } else {
119
+ end = cur [1 ];
120
+ }
121
+ }
122
+ return ans ;
123
+ };
124
+ ```
125
+
106
126
### ** C++**
107
127
108
128
``` cpp
Original file line number Diff line number Diff line change @@ -86,6 +86,26 @@ class Solution {
86
86
}
87
87
```
88
88
89
+ ### ** TypeScript**
90
+
91
+ ``` ts
92
+ function eraseOverlapIntervals(intervals : number [][]): number {
93
+ let n = intervals .length ;
94
+ if (n == 0 ) return 0 ;
95
+ intervals .sort ((a , b ) => a [1 ] - b [1 ]);
96
+ let end = intervals [0 ][1 ], ans = 0 ;
97
+ for (let i = 1 ; i < n ; ++ i ) {
98
+ let cur = intervals [i ];
99
+ if (end > cur [0 ]) {
100
+ ans ++ ;
101
+ } else {
102
+ end = cur [1 ];
103
+ }
104
+ }
105
+ return ans ;
106
+ };
107
+ ```
108
+
89
109
### ** C++**
90
110
91
111
``` cpp
Original file line number Diff line number Diff line change
1
+ function eraseOverlapIntervals ( intervals : number [ ] [ ] ) : number {
2
+ let n = intervals . length ;
3
+ if ( n == 0 ) return 0 ;
4
+ intervals . sort ( ( a , b ) => a [ 1 ] - b [ 1 ] ) ;
5
+ let end = intervals [ 0 ] [ 1 ] , ans = 0 ;
6
+ for ( let i = 1 ; i < n ; ++ i ) {
7
+ let cur = intervals [ i ] ;
8
+ if ( end > cur [ 0 ] ) {
9
+ ans ++ ;
10
+ } else {
11
+ end = cur [ 1 ] ;
12
+ }
13
+ }
14
+ return ans ;
15
+ } ;
You can’t perform that action at this time.
0 commit comments