bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 75. Sort Colors

75. Sort Colors

Leetcode Solutions

Dutch National Flag Problem

  1. Initialize p0 to 0, p2 to n - 1, and curr to 0.
  2. While curr is less than or equal to p2:
    • If nums[curr] is 0, swap nums[curr] with nums[p0] and increment both p0 and curr.
    • If nums[curr] is 2, swap nums[curr] with nums[p2] and decrement p2.
    • If nums[curr] is 1, increment curr.
  3. Continue this process until curr is greater than p2.
UML Thumbnail

Counting Sort Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...