题解 | #调整数组顺序使奇数位于偶数前面#
调整数组顺序使奇数位于偶数前面
http://www.nowcoder.com/practice/ef1f53ef31ca408cada5093c8780f44b
遍历数组将奇数和偶数分别存储,最后再将偶数数组拼在奇数数组之后
if(array.length==0 || array.length==1){ return array; } int[] oddArray=new int[array.length]; int[] evenArray = new int[array.length]; int a=0; int b=0; for(int i = 0;i<array.length;i++){ if(array[i]%2==1){ oddArray[a]=array[i]; a++; }else{ evenArray[b]=array[i]; b++; } } int bb=0; for(int j = 0;j<oddArray.length;j++){ if(oddArray[j]==0){ oddArray[j]=evenArray[bb]; bb++; }else{ continue; } } return oddArray; }