1
class Solution {
2

3
public void sortColors(int[] nums) {
4

5
int zeroIndex = 0, twoIndex = nums.length - 1, i = 0;
6
while (i <= twoIndex) {
7
if (nums[i] == 0) swap(nums, zeroIndex++, i++);
8
else if (nums[i] == 2) swap(nums, twoIndex--, i);
9
else i++;
10
}
11
}
12

13
public void swap(int[] nums, int i, int j) {
14
int temp = nums[i];
15
nums[i] = nums[j];
16
nums[j] = temp;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0