//One pass Time O(n) space O(1)
public void MoveZeroes(int[] nums) {
if(nums == null || nums.Length == 0)
{
return;
}
int temp = 0;
int nonZeroIndex = 0;
for (int i = 0; i < nums.Length; i++)
{
if (nums[i] != 0)
{
temp = nums[i];
nums[i] = 0;
nums[nonZeroIndex] = temp;
nonZeroIndex++;
}
}
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)