http://blog.csdn.net/linhuanmars/article/details/24286349
class Solution(object):
def sortColors(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
i = j = 0
for k in xrange(len(nums)):
v = nums[k]
nums[k] = 2
if v < 2:
nums[j] = 1
j += 1
if v == 0:
nums[i] = 0
i += 1
本文介绍了一种在原地修改数组的排序算法——三色旗排序算法,该算法主要用于将包含0、1、2三个整数的数组进行快速排序。通过遍历数组并将元素分为三个区间,最终实现排序。

259

被折叠的 条评论
为什么被折叠?



