class Solution(object):
# def moveZeroes(self, nums):
# """
# :type nums: List[int]
# :rtype: void Do not return anything, modify nums in-place instead.
# """
# # O(n^2)
# ls = len(nums)
# pos = 0
# while pos < ls:
# if nums[pos] == 0:
# curr = pos + 1
# while curr < ls:
# if nums[curr] != 0:
# temp = nums[curr]
# nums[curr] = nums[pos]
# nums[pos] = temp
# break
# curr += 1
# pos += 1
def moveZeroes(self, nums):
# O(n)
ls = len(nums)
n_pos = 0
for i in range(ls):
if nums[i] != 0:
temp = nums[n_pos]
nums[n_pos] = nums[i]
nums[i] = temp
n_pos += 1
Download Move Zeroes.pyLeetcode 283 Move Zeroes problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.