# Accepted python solution

• After reading from comments I realized the question don't want us to remove elements from the list, but to put non-duplicated list in the beginning and return the size of it. And OJ doesn't care about the rest of the list.

I don't understand why this question don't allow us to use del to remove element from the list. Maybe because of the definition of Array structure in C?

``````class Solution:
# @param a list of integers
# @return an integer
def removeDuplicates(self, A):
if not A:
return 0
end = len(A)
write = 1
write += 1
return write``````

• This post is deleted!

• At first, you said that the question want us to put non-duplicated list in the beginning and return the size of it. I have the same finding with you.But I don't know why the question don't care about the array.
The question said:
Given input array A = [1,1,2],Your function should return length = 2, and A is now [1,2].
Thanks

• I use 'del' in my code, and it was accepted.But it runs 136ms,too slow.Thatis my code:
class Solution(object):
def removeDuplicates(self, nums):
i,len_s = 0,len(nums)
while i<len(nums)-1:
if nums[i]==nums[i+1]:
del nums[i]
len_s -= 1
else:
i += 1
return len(nums)

• @the_important I think the nums list will be tested as well

• This post is deleted!

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.