Very easy-to-understand solutions


  • 0
    G
    public class Solution {
        public void moveZeroes(int[] nums) {
             int j =0;
             int n = nums.length;
             for (int i=0; i< n; i++){
                 if(nums[i] !=0) {
                     nums[j]=nums[i];
                     j++;
                 }
              }
             for (int x=j; x< n; x++) nums[x]=0;
        }
    }
    

Log in to reply
 

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