算法练习1——删除数组中重复值

给定 nums = [0,0,1,1,1,2,2,3,3,4],

函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。

你不需要考虑数组中超出新长度后面的元素。
class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        """j = 0
        while j < len(nums) - 1:
            if nums[j] == nums[j+1]:
                del nums[j]
            else:
                j += 1

        return len(nums)"""
       
来自Leecode

猜你喜欢

转载自blog.csdn.net/weixin_41512727/article/details/80809623
今日推荐