Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b013345

Browse files
authored
Update 0026-remove-duplicates-from-sorted-array.py
1 parent 6c90867 commit b013345

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
class Solution(object):
2-
def removeDuplicates(self, nums):
3-
"""
4-
:type nums: List[int]
5-
:rtype: int
6-
"""
7-
k = 0
8-
i = 0
9-
while i < len(nums):
10-
val = nums[i]
11-
while i + 1 < len(nums) and nums[i + 1] == val:
12-
nums.remove(val)
13-
k += 1
14-
i += 1
15-
return len(nums)
1+
class Solution:
2+
def removeDuplicates(self, nums: List[int]) -> int:
3+
L = 1
4+
5+
for R in range(1, len(nums)):
6+
if nums[R] != nums[R - 1]:
7+
nums[L] = nums[R]
8+
L += 1
9+
return L

0 commit comments

Comments
 (0)