75. Sort Colors
Input:
[2,0,2,1,1,0]
Output:
[0,0,1,1,2,2]class Solution(object):
def sortColors(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
d = collections.defaultdict(int)
for num in nums: d[num]+=1
i = 0
for num in xrange(0,3):
for t in xrange(d[num]):
nums[i] = num
i+= 1Last updated
Was this helpful?