Skip to content

Commit ce5aac3

Browse files
authored
added solution for leetcode #26. Remove duplicates from sorted array (#60)
1 parent 0fb0a47 commit ce5aac3

File tree

1 file changed

+15
-0
lines changed
  • Algorithms/Easy/26_RemoveDuplicatesFromSortedArray

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def removeDuplicates(self, nums: List[int]) -> int:
3+
# go through the array,
4+
# if nth item and (n+1)th item match, pop nth item, but don't forward
5+
# otherwise go forward
6+
7+
i = 1
8+
while i<len(nums):
9+
if nums[i-1] == nums[i]:
10+
nums.pop(i-1)
11+
else:
12+
i += 1
13+
14+
15+
return len(nums)

0 commit comments

Comments
 (0)