Leetcode # 26. Remove Duplicates from Sorted Array
- 2023.08.04
- ★ Easy LeetCode Two Pointers
https://leetcode.com/problems/remove-duplicates-from-sorted-array
Solution
重點:nums sorted in non-decreasing order
Time Complexity: O(len(nums))
Space Complexity: O(1)
(The input and output generally do not count towards the space complexity.)
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
insert_i = 1
for i in range(1, len(nums)):
if nums[i] != nums[i - 1]:
nums[insert_i] = nums[i]
insert_i += 1
return insert_i
Last Updated on 2023/08/16 by A1go