blob: 8a126dae904a5bbb0b8c679a2681fbcd5999a826 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
struct Solution;
impl Solution {
pub fn pivot_array(nums: Vec<i32>, pivot: i32) -> Vec<i32> {
let mut greater = vec![];
let mut same = 0;
let ans = vec![];
for n in nums {
if n < pivot {
ans.push(n);
} else if n == pivot {
same += 1;
} else {
greater.push(n);
}
}
for _ in 0..same {
ans.push(pivot);
}
for g in greater {
ans.push(g);
}
ans
}
}
fn main() {
let s = Solution;
let nums = vec![9,12,5,10,14,3,10];
let pivot = 10;
print!("{}", s.pivot_array(nums, pivot));
}
|