[LeetCode][python3]0026. Remove Duplicates from Sorted Array
Start the journey
N2I -2020.03.19
- My first solution
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
if not nums:
return 0
pre=nums[0]
pre_index=1
for i in nums[1:]:
if i!=pre:
nums[pre_index]=i
pre=i
pre_index+=1
#print(nums)
return pre_index
Note:
Explanation:
Notice that we have to follow the condition in the question: “Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.”