Loading...
You are given an integer array nums in which every element is 0, 1, or 2. Return the values rearranged into non-decreasing order: all the 0s first, then all the 1s, then all the 2s.
The returned array has the same length as nums and the same number of each value, so only one arrangement is correct.
Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Explanation: The array holds two 0s, two 1s and two 2s, so they come back grouped in that order.
Input: nums = [2,0,1]
Output: [0,1,2]
Explanation: One copy of each value, returned smallest to largest.
nums.lengthnums[i] is either 0, 1, or 2Click "Run" to test with sample cases or "Submit" to run all tests.