1. 程式人生 > >python leetcode 26. Remove Duplicates from Sorted Array

python leetcode 26. Remove Duplicates from Sorted Array

在原本陣列上操作即可

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        ln = len(nums)
        if ln==0:
            return 0
        j=0  
        for i in range(1,ln):
            if nums[j] != nums[i]:
                nums[
j+1]=nums[i] j=j+1 return j+1