【LeetCode】【数组】题号:*283,移动零

every blog every motto: You will never know unless you try

0. 前言

1. 正文

1.1 题目

在这里插入图片描述

1.2 题解

python:

class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """

        if not nums:
            return nums

        j = 0
        for i in range(len(nums)):
            if nums[i]:
                nums[i],nums[j] = nums[j],nums[i]
                j+=1

1.3 结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/115057179