So the goal here is to move all 0's to the end of the array but I stumble across a problem from these small lines of code.
When I use the input I get the desired output like so:
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
However, whenever I use this input:
[0,0,1]
I get this output:
[0,1,0]
When I want the output:
[1,0,0]
I have no idea why I thought I implemented this properly:
class Solution:
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
for counter in range(len(nums)):
if nums[counter] == 0:
nums.pop(counter) #Remove the 0
nums.append(0) #Add to end.
counter-=1 #Check same index just incase adjacent 0
Any input is appreciated. Thanks!