27.移除元素

26题目

class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        i = 0
        while i < len(nums):
            if nums[i] == val:
                del nums[i]
                continue
            else:
                i += 1
        return len(nums) 

评论