FunctionRacerProblemsRace

Sort Colors

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

nums holds only the numbers 0, 1 and 2 (think of red, white and blue). Rearrange it in place so all 0s come first, then all 1s, then all 2s. Return nothing.

Try to do it without calling sort.

Example 1

nums [2,0,2,1,1,0]
returns [0,0,1,1,2,2]

It becomes [0, 0, 1, 1, 2, 2].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems