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 939af48 commit 7af88a1Copy full SHA for 7af88a1
rust/57-Insert-Interval.rs
@@ -0,0 +1,21 @@
1
+pub fn insert(intervals: Vec<Vec<i32>>, mut new_interval: Vec<i32>) -> Vec<Vec<i32>> {
2
+ let mut res: Vec<Vec<i32>> = Vec::new();
3
+
4
+ for i in 0..intervals.len() {
5
+ if new_interval[1] < intervals[i][0] {
6
+ res.push(new_interval.clone());
7
+ return [res, intervals[i..].to_vec()].concat().to_vec();
8
+ } else if new_interval[0] > intervals[i][1] {
9
+ res.push(intervals[i].clone());
10
+ } else {
11
+ new_interval = vec![
12
+ new_interval[0].min(intervals[i][0]),
13
+ new_interval[1].max(intervals[i][1]),
14
+ ];
15
+ }
16
17
18
+ res.push(new_interval);
19
20
+ res
21
+}
0 commit comments