Lintcode373 Partition Array by Odd and Even solution 题解

【题目描述】

 Partition an integers array into odd number first and even number second.

分割一个整数数组,使得奇数在前偶数在后。

【题目链接】

www.lintcode.com/en/problem/partition-array-by-odd-and-even/

【题目解析】

1、将数组中的奇数和偶数分开,使用『两根指针』的方法,用快排的思路,右指针分别从数组首尾走起

2、左指针不断往右走直到遇到偶数,右指针不断往左走直到遇到奇数,交换左右指针数据。

3、重复2操作,知道左右指针相遇,算法结束。

【参考答案】

www.jiuzhang.com/solutions/partition-array-by-odd-and-even/

 

posted on 2018-04-11 21:33  bokeyyy  阅读(137)  评论(0)    收藏  举报

导航