1 class Solution {
2 public:
3 /**
4 * @param nums: a vector of integers
5 * @return: nothing
6 */
7 void partitionArray(vector<int> &nums) {
8 // write your code here
9 int size = nums.size();
10 int begin=0, end=size-1;
11
12 while(begin < end) {
13 // 指向奇数
14 while((nums[begin] & 1)==1) {
15 begin++;
16 }
17 // 指向偶数
18 while((nums[end] & 1)==0) {
19 end--;
20 }
21
22 if(begin < end) {
23 int temp = nums[begin];
24 nums[begin] = nums[end];
25 nums[end] = temp;
26 }
27 }
28 }
29 };