From 8d4606ab95a874d7a6a2f5c3c531300cf1c4e2e6 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 8 Mar 2024 16:51:55 +0000 Subject: [PATCH] Solve 26. Remove Duplicates from Sorted Array --- python/remove_duplicates_from_sorted_array.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/remove_duplicates_from_sorted_array.py diff --git a/python/remove_duplicates_from_sorted_array.py b/python/remove_duplicates_from_sorted_array.py new file mode 100644 index 0000000..117e87c --- /dev/null +++ b/python/remove_duplicates_from_sorted_array.py @@ -0,0 +1,8 @@ +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + current = nums[-1] + 1 + for i in range(len(nums)-1, -1, -1): + if nums[i] == current: + del nums[i] + else: + current = nums[i]