mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 23:07:08 +00:00
Time: 71 ms (88.49%), Space: 14.6 MB (77.98%) - LeetHub
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
class Solution(object):
|
||||||
|
def removeDuplicates(self, nums):
|
||||||
|
"""
|
||||||
|
:type nums: List[int]
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
oldIndex = 1
|
||||||
|
newIndex = 1
|
||||||
|
lastNum = nums[0]
|
||||||
|
|
||||||
|
while oldIndex < len(nums):
|
||||||
|
if nums[oldIndex] == lastNum:
|
||||||
|
oldIndex += 1
|
||||||
|
else:
|
||||||
|
nums[newIndex] = nums[oldIndex]
|
||||||
|
newIndex += 1
|
||||||
|
lastNum = nums[oldIndex]
|
||||||
|
|
||||||
|
return len(nums[:newIndex])
|
||||||
Reference in New Issue
Block a user