Sort Colors

Medium Solved

Description

Given an array nums containing only 0, 1, and 2, sort the array in-place so that all 0s come first, followed by 1s, then 2s.

Examples:

Input: [2,0,2,1,1,0]

Output: [0,0,1,1,2,2]

Input: [2,0,1]

Output: [0,1,2]

Note:

Runner expects a single line JSON array and prints the sorted array.

Your Submissions

No submissions yet.

Discuss

Discuss counting vs Dutch National Flag algorithm.

Test Cases