第一次解法,循环解法(java)
- java中的循环 看这里 采用简洁写法,其结果类似与正常写法,直接遍历元素,当然也可以直接遍历变量。 ```java
class Solution { public int[] sortArrayByParityII(int[] A) { int len = A.length; int[] result = new int[len];
int i = 0;int j = 1;for(int x : A){if(x%2==0){result[i] = x;i += 2;}else{result[j] = x;j+=2;}}return result;}
