Sunday, September 7, 2014

Leetcode: Remove Duplicates from Sorted Array @Python

class Solution:
    # @param a list of integers
    # @return an integer
    def removeDuplicates(self, A):
        if not A: return 0
        fast=slow=0
        n=len(A)
        while fast<n:
            if A[slow]!=A[fast]:
                slow+=1
                A[slow]=A[fast]
            fast+=1
        return slow+1

No comments :

Post a Comment