1.问题描述:
给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度。
不要使用额外的数组空间,必须在原地没有额外空间的条件下完成。
2.样例:
给出数组A =[1,1,2],你的函数应该返回长度2,此时A=[1,2]。
3.代码:
class Solution:
"""
@param: nums: An ineger array
@return: An integer
"""
def removeDuplicates(self, nums):
# write your code here
length=len(nums)
nowlength=length
for i in range(length-1):
while i<nowlength-1 and nums[i]==nums[i+1]:
del nums[i+1]
nowlength-=1
ans=len(nums)
return ans