# 283. Move Zeroes # https://leetcode.com/problems/move-zeroes/ # # 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. # exemplo: dada a cadeia '00001' resultado final é '10000' def moveZeroes(self, nums: list[int]) -> None: """ Do not return anything, modify nums in-place instead. """ for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[j] != 0: nums[i] = nums[j] nums[j] = 0 if nums[i] == 0 and i < len(nums)-1: if nums[i+1] != 0: nums[i] = nums[i+1] nums[i+1] = 0