双指针
左指针确定不重复值,右指针遍历数组
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
left=0
for right in range(1,len(nums)):
if nums[left] != nums[right]:
left +=1
nums[left] = nums[right]
return left+1
时间复杂度:
O
(
N
)
O(N)
O(N)
空间复杂度:
O
(
1
)
O(1)
O(1)