奇偶分割数组
code
class Solution {
public:
/**
* @param nums: a vector of integers
* @return: nothing
*/
void partitionArray(vector<int> &nums) {
// write your code here
int size = nums.size();
int begin=0, end=size-1;
while(begin < end) {
// 指向奇数
while((nums[begin] & 1)==1) {
begin++;
}
// 指向偶数
while((nums[end] & 1)==0) {
end--;
}
if(begin < end) {
int temp = nums[begin];
nums[begin] = nums[end];
nums[end] = temp;
}
}
}
};