'''
Created on 2015年11月9日
@author: SphinxW
'''
# 刪除排序數組中的重復數字
#
# 給定一個排序數組,在原數組中刪除重復出現的數字,使得每個元素只出現一次,并且返回新的數組的長度。
#
# 不要使用額外的數組空間,必須在原地沒有額外空間的條件下完成。
# 樣例
#
# 給出數組A =[1,1,2],你的函數應該返回長度2,此時A=[1,2]。
class Solution:
"""
@param A: a list of integers
@return an integer
"""
def removeDuplicates(self, A):
# write your code here
index = 1
if len(A) == 0:
return None
fir = A[0]
while index < len(A):
if A[index] <= fir:
del A[index]
else:
fir = A[index]
index += 1
return len(A)
s = Solution()
A = [1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9]
print(s.removeDuplicates(A))