题目链接:https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/
题目如下:
class Solution {
public:
vector<int> exchange(vector<int>& nums) {
int first=0,last=nums.size()-1;
while(first<last){
if(nums[first]%2==0&&nums[last]%2!=0){
int temp=nums[first];
nums[first]=nums[last];
nums[last]=temp;
}
else{
if(nums[first]%2!=0) first++;
if(nums[last]%2==0) last--;
}
}
return nums;
}
};