class Solution {
public int[] sortArrayByParity(int[] A) {
int[] res = new int[A.length];
int index = 0;
for(int i=0; i < A.length; i++){
if(A[i]%2 == 0)
res[index++] = A[i];
}
for(int i=0; i < A.length; i++){
if(A[i]%2 == 1)
res[index++] = A[i];
}
return res;
}
}
LeetCode 905. Sort Array By Parity
最新推荐文章于 2025-02-12 22:45:00 发布