0ms Java solution


  • 0
    A
    public class Solution {
        public void moveZeroes(int[] nums) {
            int count_0 = 0;
            int index = 0;
            for(int i = 0; i < nums.length; i++){
                if(nums[i] == 0){
                    count_0++;
                }
                if(nums[i] != 0){
                    nums[index] = nums[i];
                    index++;
                }
            }
            for(int i = nums.length - count_0; i < nums.length; i++){
                nums[i] = 0;
            }
        }
    }
    

    Edit: I think its the site, but now its showing 1 ms, but initially it was 0ms.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.