当前位置:首页>财经>正文

LeetCode,移除排序数组中重复元素,用python

2023-04-15 01:14:28 互联网 未知 财经

 LeetCode,移除排序数组中重复元素,用python

LeetCode,移除排序数组中重复元素,用python

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