美文网首页
【Leetcode】【Python】283. Move Zero

【Leetcode】【Python】283. Move Zero

作者: 小歪与大白兔 | 来源:发表于2017-10-22 13:19 被阅读0次

问题描述:

Paste_Image.png

代码示例:

class Solution(object):
    def moveZeroes(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        n = len(nums)
        count = 0  #count记录数组中不为0的元素的个数
        for value in nums:
            if value != 0:
                nums[count] = value
                count += 1
        for i in range(count,n):
            nums[i] = 0

相关文章

网友评论

      本文标题:【Leetcode】【Python】283. Move Zero

      本文链接:https://www.haomeiwen.com/subject/dqvguxtx.html