435. Non-overlapping Intervals Medium

@problem@discussion
#Array#Dynamic Programming#Greedy#Sorting



1/**
2 * [435] Non-overlapping Intervals
3 *
4 * Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
5 *  
6 * Example 1:
7 * 
8 * Input: intervals = [[1,2],[2,3],[3,4],[1,3]]
9 * Output: 1
10 * Explanation: [1,3] can be removed and the rest of the intervals are non-overlapping.
11 * 
12 * Example 2:
13 * 
14 * Input: intervals = [[1,2],[1,2],[1,2]]
15 * Output: 2
16 * Explanation: You need to remove two [1,2] to make the rest of the intervals non-overlapping.
17 * 
18 * Example 3:
19 * 
20 * Input: intervals = [[1,2],[2,3]]
21 * Output: 0
22 * Explanation: You don't need to remove any of the intervals since they're already non-overlapping.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= intervals.length <= 10^5
28 * 	intervals[i].length == 2
29 * 	-5 * 10^4 <= starti < endi <= 5 * 10^4
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/non-overlapping-intervals/
35// discuss: https://leetcode.com/problems/non-overlapping-intervals/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn erase_overlap_intervals(intervals: Vec<Vec<i32>>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_435() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.