diff --git a/src/remove_duplicates_from_sorted_array.py b/src/remove_duplicates_from_sorted_array.py index 548386d..44879f6 100644 --- a/src/remove_duplicates_from_sorted_array.py +++ b/src/remove_duplicates_from_sorted_array.py @@ -1,13 +1,11 @@ class Solution: def removeDuplicates(self, nums: list[int]) -> int: - if not nums: - return 0 - - to_insert = 1 + j = 1 for i in range(1, len(nums)): - if nums[i] != nums[to_insert - 1]: - nums[to_insert] = nums[i] - to_insert += 1 + if nums[i - 1] == nums[i]: + continue + nums[j] = nums[i] + j += 1 - return to_insert + return j