Sort Colors

Given an array with objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. You must solve this problem without using the library's sort function.

Constraints

  • n == nums.length
  • 1 <= n <= 300
  • nums[i] is either 0, 1, or 2.
Saving… · 2 lines
class Solution:
def sortColors(self, nums: List[int]) -> None:
Console

Click Run to execute sample tests.