Skip to content

Instantly share code, notes, and snippets.

@eebasadre20
Created December 7, 2019 05:14
Show Gist options
  • Select an option

  • Save eebasadre20/88be3fcfe13ee664473342bb3b081212 to your computer and use it in GitHub Desktop.

Select an option

Save eebasadre20/88be3fcfe13ee664473342bb3b081212 to your computer and use it in GitHub Desktop.
LeetCode - Move Zeroes
# @param {Integer[]} nums
# @return {Void} Do not return anything, modify nums in-place instead.
def move_zeroes(nums)
x = 0
y = x + 1
loop do
break if y >= nums.length
if nums[x] == 0 && nums[y] != 0
nums[x], nums[y] = nums[y], nums[x]
x += 1
y += 1
else
x += 1 if nums[x] != 0
y += 1
end
end
nums
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment