coding = utf-8
'''
Created on 2015年11月10日
@author: SphinxW
'''
# 删除排序数组中的重复数字 II
#
# 跟进“删除重复数字”:
#
# 如果可以允许出现两次重复将如何处理?
#
#
# 样例
#
# 给出数组A =[1,1,1,2,2,3],你的函数应该返回长度5,此时A=[1,1,2,2,3]。
class Solution:
"""
@param A: a list of integers
@return an integer
"""
def removeDuplicates(self, A):
# write your code here
if len(A) == 0:
return 0
A.sort()
headIndex = 0
count = 1
delCount = 0
thisNum = None
while headIndex + delCount < len(A):
if thisNum == A[headIndex] and count > 1:
del A[headIndex]
elif thisNum == A[headIndex] and count == 1:
count += 1
headIndex += 1
else:
thisNum = A[headIndex]
headIndex += 1
count = 1
return headIndex + 1