QuestionGiven an arraynumswithnobjects colored red, white, or blue, sort themin-placeso that objects of the same color are adjacent, with the colors in the order red, white, and blue.We will use the integers0,1, and2to represent the color red, white, and blue, respectively.You must solve this problem without using the library's sort function.Example 1:Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]AlgorithmYou cannot assume the amount of 0, 1, 2 are the same.Basically the idea is to put the 0s at the left side and 2s at the right side, and the positions left in the middle are 1sThere should
...
继续阅读
(44)