1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class Solution { public void reOrderArray(int [] array) { fint leftIndex = -1; int rightIndex = -1; boolean flag = true; for (int i = 0; i < array.length; i++) { if((array[i]&1)==1&& rightIndex<i){ rightIndex = i; } if(flag&&(array[i]&1)==0&&leftIndex<i){ leftIndex = i; flag=false; } if(leftIndex < rightIndex&&leftIndex!=-1){ changeIndex(array,leftIndex,rightIndex); rightIndex = leftIndex; leftIndex++; } } }
|