My solution with Python seems 'in place' without copy of the array,but cost more time

  • 0

    it's my solution with python ,and it seems in place, doesn't cost other memory, without copy of the array.But it costs more time, who can help me to improve this? thanks a lot

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

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.