創兩個vector存even和odd,再重丟進去(但這樣分數好低...
class Solution {
public:
vector<int> sortArrayByParity(vector<int>& nums) {
int n = nums.size();
vector<int> even, odd;
for(int i = n - 1; i >= 0; i--){
if(nums[i] % 2 == 1){
odd.push_back(nums[i]);
cout << nums[i];
}
else{
even.push_back(nums[i]);
}
}
for(int i = 0; i < even.size(); i++){
nums[i] = even[i];
//cout << nums[i];
}
for(int i = 0; i < odd.size(); i++){
nums[i + even.size()] = odd[i];
//cout << nums[i];
}
return nums;
}
};