Search topics...

Sort Colors

medium
arrayTime: O(n)Space: O(1)Frequency: 4

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]
sorting