Remove Duplicates from Sorted Array @ LeetCode (Python)
kitt
posted @ 2014年2月14日 22:01
in LeetCode
, 3450 阅读
使用两个指针
class Solution:
# @param a list of integers
# @return an integer
def removeDuplicates(self, A):
if not A: return 0
slow = 0
for fast in xrange(len(A)):
if A[fast] == A[slow]:
continue
else:
slow += 1
A[slow] = A[fast]
return slow + 1