congr / world

2 stars 1 forks source link

LeetCode : 283. Move Zeroes #487

Closed congr closed 5 years ago

congr commented 5 years ago

https://leetcode.com/problems/move-zeroes/

image

congr commented 5 years ago
class Solution {
    public void moveZeroes(int[] nums) {
        int k = 0;
        for (int i = 0; i < nums.length; i++) 
            if (nums[i] != 0) nums[k++] = nums[i];

        while (k < nums.length) nums[k++] = 0;
    }
}