Tuesday, November 17, 2015

[leetcode]Move Zeroes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
public class Solution {
    public void moveZeroes(int[] nums) {
        int spot = 0;
        for (int i = 0; i < nums.length; i++){
         if (nums[i] != 0){
          nums[spot++] = nums[i];
         }
        }
        for (int i = spot; i < nums.length; i++){
         nums[i] = 0;
        }
    }
}

No comments:

Post a Comment