[leetcode]Move Zeroes

Posted 阿牧遥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[leetcode]Move Zeroes相关的知识,希望对你有一定的参考价值。

双指针

class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        i = j = 0
        while j < len(nums):
            if nums[j] == 0:
                pass
            else:
                nums[i] = nums[j]
                i += 1
            j += 1
        while i < len(nums):
            nums[i] = 0
            i += 1

  

以上是关于[leetcode]Move Zeroes的主要内容,如果未能解决你的问题,请参考以下文章

leetcode 283. Move Zeroes

leetcode笔记:Move Zeroes

LeetCode:Move Zeroes

Leetcode.283 | Move Zeroes(Python)

LeetCode 283. Move Zeroes

Leetcode 283. Move Zeroes