# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.8.3 32-bit
#     language: python
#     name: python38332bit19a78f05c6cb434680bc6f0964f662fa
# ---

# # Challenge 010 - Move Zeroes
# This challenge is taken from LeetCode - 283. Move Zeroes (https://leetcode.com/problems/move-zeroes/).
#
# ## Problem
# Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
#
# Note that you must do this in-place without making a copy of the array.
#
#
# Example 1:
# ```
# Input: nums = [0,1,0,3,12]
# Output: [1,3,12,0,0]
# ```
#
# Example 2:
# ```
# Input: nums = [0]
# Output: [0]
# ``` 
#
# Constraints:
# ```
# 1 <= nums.length <= 104
# -231 <= nums[i] <= 231 - 1
# ```
#
# Follow up: Could you minimize the total number of operations done?
#
# ## Solution

class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: None Do not return anything, modify nums in-place instead.
        """
        for i in range(len(nums)-1, -1, -1):
            if nums[i] == 0:
                nums.append(0)
                nums.pop(i)

StarcoderdataJupyterScriptsDedupFiltered