F_G

许多问题需要说清楚就可以&&走永远比跑来的重要

导航

[Leetcode] Sort Colors

[1] http://blog.csdn.net/lanxu_yy/article/details/11907615

每当遇到0,则放到当前可放置的最左端‘如果遇到2,则放到当前可放置位置的最右边。

 具体的过程:

如果当前元素是2,那么将其交换到最右边,rightindex--,同时当前index不变

如果当前元素是0,那么currentindex++,leftindex++;

如果当前元素是1,那么currentindex++

[2]

使用两次快速排序,

首先,将0全放到1,2前面,然后在对1,2子集进行快排

O(n)

posted on 2015-07-16 21:29  F_G  阅读(109)  评论(0编辑  收藏  举报