fix34

public int[] fix34(int[] nums) {
  
  int i3=0;
  int i4=0;
  int temp=0;
  
  while( (i3<nums.length)&&(i4<nums.length))
  {
      while(i3<nums.length){
        if(nums[i3]==3) break;
        i3++;
      }
      
      while(i4<nums.length){
        if(nums[i4]==4) break;
        i4++;
      }
      
      if(i3 < nums.length-1){
        temp=nums[i4];
        nums[i4]=nums[i3+1];
        nums[i3+1]=temp;
        i3++;
        i4++;
        
      }
      
      
    
  }
  return nums;
}

http://codingbat.com/prob/p159339

posted @ 2017-02-15 22:03  友哥  阅读(112)  评论(0编辑  收藏  举报