Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainevsia committed Oct 3, 2024
1 parent 0202122 commit 57e687c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions notes/src/day36/lc56.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ public:
这个 很直接
```rust
struct Solution {}
impl Solution {
pub fn merge(mut intervals: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let mut res: Vec<Vec<i32>> = Vec::new();
intervals.sort_by_key(|v| v[0]);
let mut left: i32 = intervals[0][0];
let mut right: i32 = intervals[0][1];
intervals.iter().skip(1usize).for_each(|v| {
if v[0] <= right {
right = std::cmp::max(v[1], right);
} else {
// non overlap
res.push(vec![left, right]);
left = v[0];
right = v[1];
}
});
res.push(vec![left, right]);
res
}
}
```

0 comments on commit 57e687c

Please sign in to comment.