題目來源:
題目分析:
實現代碼:
class Solution:
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
i=1 #用來遍歷整個列表
j=1 #用來記錄不同元素的個數
n=len(nums)
if (len(nums)==0):
return 0
else:
while(i<n):
if(nums[i]==nums[i-1]):
i+=1
else:
nums[j]=nums[i]
j+=1
i+=1
return j