Given an array nums containing only the values 0, 1, and 2 (representing red, white, and blue), sort the array in-place so that all 0s come first, then all 1s, then all 2s.
This is known as the Dutch National Flag problem, named after the three-colored flag of the Netherlands.
You should solve this in a single pass with O(1) extra space. Do not use a library sort function.
Return the sorted array.
nums = [2, 0, 2, 1, 1, 0][0, 0, 1, 1, 2, 2]nums = [2, 0, 1][0, 1, 2]nums = [0][0]1 <= nums.length <= 300nums[i] is 0, 1, or 2Run your code to see results
Use Cmd+Enter to run