26. Remove Duplicates from Sorted Array
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 60% Topics: Array, Two Pointers
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
# @param a list of integers
# @return an integer
def removeDuplicates(self, A):
if not A:
return 0
last = 0
for i in xrange(len(A)):
if A[last] != A[i]:
last += 1
A[last] = A[i]
return last + 1
Solution from kamyu104/LeetCode-Solutions · MIT