Java simple Code


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

Log in to reply
 

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