0
点赞
收藏
分享

微信扫一扫

Leetcode-数组学习1

小布_cvg 2022-02-03 阅读 71

今天把Kaggle里的python简单入门结束了,并开始学习了Leetcode里的数组,算是对自己掌握不太多的python进行练习,也属于是新年新气象了。废话不多说,开始正文。

1. 删除排序数组中的重复项

提示:

  • 0 <= nums.length <= 3 * 10^4
  • -10^4 <= nums[i] <= 10^4
  • nums已按升序排列

Python代码如下

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for i in range(len(nums) - 1, 0, -1):
            if nums[i] == nums[i - 1]:
                del nums[i]
        return len(nums)
举报

相关推荐

0 条评论