#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 24 02:33:18 2017

@author: Steven

Given an array nums, write a function to move all 0's to the end 
while maintaining the relative order of the nonzero elements.
"""
class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        if(nums is None or len(nums)==0):
            return None
            print("invalid input")
        pos=0
        for i in range(0, len(nums)):
            if(nums[i]!=0):
                nums[pos]=nums[i]
                pos+=1
        #print(pos)
        while(pos<=len(nums)-1):
            nums[pos]=0
            pos+=1
        return(nums)
        
        
def main():
    nums=[1,0,0,2,3]
    s=Solution()
    print(s.moveZeroes(nums)==[1, 2, 3, 0, 0])
    print('done')
   
main()
                

