LeetCode: Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once.
My code works for all of the test cases so far, except [1, 1, 1, 1]. In that case, it is only going to [1, 1] and not removing the duplicate 1
def removedup(nums):
for n in nums:
if nums.count(n) > 1:
nums.remove(n)
return(nums)
removedup([1,1,2]) #works
removedup([1,1,1,1]) #doesnt work
New contributor
None is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.