一共就三个数,可用双端队列啊!!!最小的插入到队首,最大插入到队尾!!!
class Solution(object):
def sortColors(self, nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
queue = []
t = 0
for i in nums:
if i < 1:
queue.insert(0, i)
t += 1
elif i > 1:
queue.append(i)
else:
queue.insert(t, i)
nums[:] = queue
网友评论