Sort three colours
Mediumarraytwo pointerssorting
nums holds only 0, 1 and 2 (red, white, blue). Sort it in place in one pass without a sort function, and return it.
Example 1
Input: nums = [2,0,2,1,1,0] Output: [0,0,1,1,2,2]
Example 2
Input: nums = [2,0,1] Output: [0,1,2]
Constraints
- 1 ≤ nums.length ≤ 300
- nums[i] is 0, 1 or 2
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int[]} nums
* @return {int[]}
*/
function sortColors(nums) {
}