1. 程式人生 > >LeetCode in Python: Remove Duplicates from Sorted Array

LeetCode in Python: Remove Duplicates from Sorted Array

LeetCode in Python

Remove Duplicates from Sorted Array (Easy)

class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        index = 1
        for i in range(1, len(nums)):
            if nums[i] != nums[index-1]:
                nums[
index] = nums[i] index += 1 return index s = Solution() nums = [1, 1, 1, 2, 3, 5, 7] index = s.removeDuplicates(nums) print(index)