File tree Expand file tree Collapse file tree 1 file changed +1
-38
lines changed
Solution/435. Non-overlapping Intervals Expand file tree Collapse file tree 1 file changed +1
-38
lines changed Original file line number Diff line number Diff line change 11---
22comments : true
33difficulty : Medium
4- edit_url : https://github.com/doocs/leetcode/edit/main/solution/0400-0499/0435.Non-overlapping%20Intervals/README_EN.md
4+ edit_url : Antim
55tags :
66 - Greedy
77 - Array
1313
1414# [ 435. Non-overlapping Intervals] ( https://leetcode.com/problems/non-overlapping-intervals )
1515
16- [ 中文文档] ( /solution/0400-0499/0435.Non-overlapping%20Intervals/README.md )
17-
1816## Description
1917
2018<!-- description:start -->
@@ -136,41 +134,6 @@ public:
136134};
137135```
138136
139- #### Go
140-
141- ```go
142- func eraseOverlapIntervals(intervals [][]int) int {
143- sort.Slice(intervals, func(i, j int) bool {
144- return intervals[i][1] < intervals[j][1]
145- })
146- ans := len(intervals)
147- pre := math.MinInt32
148- for _, e := range intervals {
149- l, r := e[0], e[1]
150- if pre <= l {
151- ans--
152- pre = r
153- }
154- }
155- return ans
156- }
157- ```
158-
159- #### TypeScript
160-
161- ``` ts
162- function eraseOverlapIntervals(intervals : number [][]): number {
163- intervals .sort ((a , b ) => a [1 ] - b [1 ]);
164- let [ans, pre] = [intervals .length , - Infinity ];
165- for (const [l, r] of intervals ) {
166- if (pre <= l ) {
167- -- ans ;
168- pre = r ;
169- }
170- }
171- return ans ;
172- }
173- ```
174137
175138<!-- tabs:end -->
176139
You can’t perform that action at this time.
0 commit comments