# Move Zeroes (Leetcode 283)

Problem Link: <https://leetcode.com/problems/move-zeroes/>

#### If order of elements matter:

```python
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        
        # If order matters, use the below code
        n=len(nums)
        i=0
        j=0
        while(j<n):
            if(nums[j]!=0):
                nums[i],nums[j]=nums[j],nums[i]
                j+=1
                i+=1
            else:
                j+=1
```

#### If order of elements doesn't matter (Dutch National Flag Algo):

```python
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        
        n=len(nums)
        # If order doesn't matter, use Dutch National Flag Algorithm 
        i=0
        j=n-1
        while(i<j):
            if(nums[i]==0 and nums[j]!=0):
                nums[i],nums[j]=nums[j],nums[i]
                i+=1
                j-=1
            elif(nums[i]!=0 and nums[j]==0):
                i+=1
                j-=1
            elif(nums[i]==0 and nums[j]==0):
                j-=1
            elif(nums[i]!=0 and nums[j]!=0):
                i+=1
```
