美文网首页
有序数组去重

有序数组去重

作者: 不识地理不懂距离 | 来源:发表于2019-02-17 09:12 被阅读0次

    O(1)内存消耗:(当然了,用set直接去掉重复元素不用写)

    class Solution(object):

        def removeDuplicates(self, nums):

            """

            :type nums: List[int]

            :rtype: int

            """

            if len(nums)==0:

                return 0

            i = 0

            for j in range(1,len(nums)):

                if nums[j]!= nums[i]:

                    i = i+1

                    nums[i] = nums[j]

            return i+1

    相关文章

      网友评论

          本文标题:有序数组去重

          本文链接:https://www.haomeiwen.com/subject/xnnweqtx.html