其他分享
首页 > 其他分享> > LeetCode contest 102

LeetCode contest 102

作者:互联网

https://leetcode-cn.com/contest/weekly-contest-102/problems/sort-array-by-parity/

水题
我的解决方案:

class Solution {
    public int[] sortArrayByParity(int[] A) {
        int[] B = new int[A.length];
        int cnt=0;
        for(int i=0;i<A.length;i++) {
            if(A[i]%2==0)
                B[cnt++] = A[i];
        }
        for(int i=0;i<A.length;i++) {
            if(A[i]%2==1)
                B[cnt++] = A[i];
        }
        return B;
    }
}

标签:parity,cn,水题,contest,int,102,LeetCode
来源: https://blog.51cto.com/u_12534050/2953444