mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 12:15:58 +08:00
@ -329,5 +329,31 @@ object Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rust
|
||||||
|
|
||||||
|
```Rust
|
||||||
|
impl Solution {
|
||||||
|
fn max(a: i32, b: i32) -> i32 {
|
||||||
|
if a > b { a } else { b }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn merge(intervals: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
|
||||||
|
let mut intervals = intervals;
|
||||||
|
let mut result = Vec::new();
|
||||||
|
if intervals.len() == 0 { return result; }
|
||||||
|
intervals.sort_by(|a, b| a[0].cmp(&b[0]));
|
||||||
|
result.push(intervals[0].clone());
|
||||||
|
for i in 1..intervals.len() {
|
||||||
|
if result.last_mut().unwrap()[1] >= intervals[i][0] {
|
||||||
|
result.last_mut().unwrap()[1] = Self::max(result.last_mut().unwrap()[1], intervals[i][1]);
|
||||||
|
} else {
|
||||||
|
result.push(intervals[i].clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||||
|
Reference in New Issue
Block a user