Search topics...
All Problems
Was this helpful?
MediumarrayExpected: O(n) time, O(1) space
sorting

Problem

Given an array with objects colored red (0), white (1), or blue (2), sort them in-place in order.

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]
Reference solution unlocks after your first submission
Loading...