You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array.
varmoveZeroes=function(nums){//we do not need to traverse i, just initialize it to 0, and move its index accordingly.leti=0;for(letj=0;j<nums.length;j++){//as long as nums[j] is not 0, we move the num[j] to nums[i], so original num[j] becomes 0. if(nums[j]!==0){nums[i]=nums[j];//since current nums[i] is not 0, we move ii++;}}//from the position of i, put all 0's until the nedfor(letk=i;k<nums.length;k++){nums[k]=0;}}
The text was updated successfully, but these errors were encountered:
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array.
The text was updated successfully, but these errors were encountered: