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 d88e61e commit 21ca8e2Copy full SHA for 21ca8e2
rust/0075-sort-colors.rs
@@ -0,0 +1,30 @@
1
+impl Solution {
2
+ pub fn sort_colors(nums: &mut Vec<i32>) {
3
+ for i in 1..nums.len() {
4
+ let mut j = i;
5
+ while j > 0 && nums[j] < nums[j - 1] {
6
+ nums.swap(j, j - 1);
7
+ j = j - 1;
8
+ }
9
10
11
+}
12
+
13
+/*
14
+* Solution using counting sort
15
+*/
16
17
18
+ let mut count = [0; 3];
19
+ for num in nums.iter() {
20
+ count[*num as usize] += 1;
21
22
+ let mut i = 0;
23
+ for (num, c) in count.iter().enumerate() {
24
+ for _ in 0..*c {
25
+ nums[i] = num as i32;
26
+ i += 1;
27
28
29
30
0 commit comments