Skip to content

Commit b8bcc05

Browse files
authored
Added solution for 2161
1 parent a4c5d4d commit b8bcc05

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
impl Solution {
2+
// Create 3 vectors: one containing values less than pivot, another equal to pivot and third containing values greater than pivot. Then return all 3 vectors concatenated as a single vector
3+
pub fn pivot_array(nums: Vec<i32>, pivot: i32) -> Vec<i32> {
4+
let mut less_than_pivot = Vec::new();
5+
let mut equal_to_pivot = Vec::new();
6+
let mut more_than_pivot = Vec::new();
7+
for num in nums {
8+
if num < pivot {
9+
less_than_pivot.push(num);
10+
} else if num > pivot {
11+
more_than_pivot.push(num);
12+
} else {
13+
equal_to_pivot.push(num);
14+
}
15+
}
16+
less_than_pivot.extend(equal_to_pivot);
17+
less_than_pivot.extend(more_than_pivot);
18+
return less_than_pivot;
19+
}
20+
}

0 commit comments

Comments
 (0)