Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2046 from alexprudhomme/0075-sort-colo…
Browse files Browse the repository at this point in the history
…rs.cs

Create: 0075-sort-colors.cs
  • Loading branch information
tahsintunan authored Jan 16, 2023
2 parents d142177 + 50a52af commit 2db3b57
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions csharp/0075-sort-colors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Solution {
public void SortColors(int[] nums) {
int low = 0;
int high = nums.Length - 1;
int mid = 0;

while (mid <= high) {
switch (nums[mid]) {
case 0:
int temp0 = nums[low];
nums[low] = nums[mid];
nums[mid] = temp0;
low++;
mid++;
break;
case 1:
mid++;
break;
case 2:
int temp2 = nums[mid];
nums[mid] = nums[high];
nums[high] = temp2;
high--;
break;
}
}
}
}

0 comments on commit 2db3b57

Please sign in to comment.