905. Sort Array By Parity

将数组排序 奇数在前 偶数在后

用快速排序中的partition算法

class Solution {
public:
    vector<int> sortArrayByParity(vector<int>& A) {
        int i=-1;
        for(int j=0;j<A.size();++j){
            if(A[j]%2==0){
                i++;
                swap(A[i],A[j]);
            }     
        }
        return A;
    }
};
原文地址:https://www.cnblogs.com/learning-c/p/9740764.html