LintCode Q100 Remove Duplicates from Sorted Array in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2016年11月29日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
"""
@param A: a list of integers
@return an integer
"""
def removeDuplicates(self, A):
# write your code here
if len(A) <= 1:
return len(A)
runner = 1
current = 1
last = A[0]
while runner < len(A):
if A[runner] == last:
runner += 1
else:
last = A[runner]
A[current] = last
current += 1
runner += 1
return current
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。