Sort Array By Parity II
给一个数组, 一半是奇数, 一半是偶数. 按照index的奇偶, 分配数字的奇偶.
class Solution {
public int[] sortArrayByParityII(int[] nums) {
int[] res = new int[nums.length];
int i = 0;
int j = 1;
for(int n : nums){
if(n % 2 == 0){
res[i] = n;
i+=2;
}
else
{
res[j] = n;
j+=2;
}
}
return res;
}
}