Created
September 8, 2020 14:01
-
-
Save riyafa/98712514b7235db9383ae912061c93a6 to your computer and use it in GitHub Desktop.
Solution for LeetCode Move Zeroes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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