We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0202122 commit 57e687cCopy full SHA for 57e687c
notes/src/day36/lc56.md
@@ -26,3 +26,27 @@ public:
26
27
这个 很直接
28
29
+
30
+```rust
31
+struct Solution {}
32
+impl Solution {
33
+ pub fn merge(mut intervals: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
34
+ let mut res: Vec<Vec<i32>> = Vec::new();
35
+ intervals.sort_by_key(|v| v[0]);
36
+ let mut left: i32 = intervals[0][0];
37
+ let mut right: i32 = intervals[0][1];
38
+ intervals.iter().skip(1usize).for_each(|v| {
39
+ if v[0] <= right {
40
+ right = std::cmp::max(v[1], right);
41
+ } else {
42
+ // non overlap
43
+ res.push(vec![left, right]);
44
+ left = v[0];
45
+ right = v[1];
46
+ }
47
+ });
48
49
+ res
50
51
+}
52
+```
0 commit comments