Problems178
Search for a command to run...
Try your own input
Change the array and replay the algorithm from step one.
Current step
Dutch National Flag: sort 0s (red), 1s (white), 2s (blue) in one pass.
Dutch National Flag
1function sortColors(nums) {//low: 0mid: 0high: 52 let low = 0, mid = 0, high = nums.length - 1;3 while (mid <= high) {4 if (nums[mid] === 0) {5 [nums[low], nums[mid]] = [nums[mid], nums[low]];6 low++; mid++;7 } else if (nums[mid] === 1) {8 mid++;9 } else {10 [nums[mid], nums[high]] = [nums[high], nums[mid]];11 high--;12 }13 }14}