Skip to content

Commit 2db3b57

Browse files
authored
Merge pull request #2046 from alexprudhomme/0075-sort-colors.cs
Create: 0075-sort-colors.cs
2 parents d142177 + 50a52af commit 2db3b57

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

csharp/0075-sort-colors.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class Solution {
2+
public void SortColors(int[] nums) {
3+
int low = 0;
4+
int high = nums.Length - 1;
5+
int mid = 0;
6+
7+
while (mid <= high) {
8+
switch (nums[mid]) {
9+
case 0:
10+
int temp0 = nums[low];
11+
nums[low] = nums[mid];
12+
nums[mid] = temp0;
13+
low++;
14+
mid++;
15+
break;
16+
case 1:
17+
mid++;
18+
break;
19+
case 2:
20+
int temp2 = nums[mid];
21+
nums[mid] = nums[high];
22+
nums[high] = temp2;
23+
high--;
24+
break;
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)