class Solution:
# @param a list of integers
# @return an integer
def removeDuplicates(self, A):
if not A:
return 0
newTail = 0
for i in range(1, len(A)):
if A[i] != A[newTail]:
newTail += 1
A[newTail] = A[i]
return newTail + 1
Simple Python solution  O(n)

Sorry, I didn't read your code carefully. Now I find out how it works. Can you help me figure out why I got an output limit error? Thx a lot.
class Solution: ''' @param integer[] nums @return integer ''' def removeDuplicates(self, nums): i = 0 while i < (len(nums)  1): if nums[i] is nums[i+1]: del nums[i] else: i += 1 return len(nums)

@yulin_ we are given a sorted array in this problem, and so nums = [1,2,1] is illegal

@AaronWuu note that "Do not allocate extra space for another array, you must do this in place with constant memory", so we should change the element order in nums

@wjymath do you mean when we use function "set", we are actually creating a new array?

@bdeng3 yeah~ notice the doc of set below
class set(object)
 set() > new empty set object
 set(iterable) > new set object
