75. Sort Colors

use bucket sort

T: O(n)

S: O(1)

use pivot partition, run 2 times partition

time: O(n)

space: O(1)

The problem is known as Dutch National Flag Problem and first was proposed by Edsger W. Dijkstra. The idea is to attribute a color to each number and then arrange them following the order of colors on the Dutch flag.

T: O(n)

S: O(1)

Last updated

Was this helpful?