Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created September 8, 2020 14:01
Show Gist options
  • Save riyafa/98712514b7235db9383ae912061c93a6 to your computer and use it in GitHub Desktop.
Save riyafa/98712514b7235db9383ae912061c93a6 to your computer and use it in GitHub Desktop.
Solution for LeetCode Move Zeroes
public class MoveZeros {
public void moveZeroes(int[] nums) {
int i = 0;
int j = 0;
while(i < nums.length && j < nums.length) {
if(nums[i] != 0) {
i++;
} else if(j <= i || nums[j] == 0) {
j++;
} else {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;j++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment