Skip to content

Commit

Permalink
Create 80._Remove_Duplicates_from_Sorted_Array_II.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansumanbhujabal authored Jul 15, 2024
1 parent c7a2d09 commit 54fab29
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Python_Problems/80._Remove_Duplicates_from_Sorted_Array_II.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
# num=sorted(nums)
# for value in num:
# if num.count(value)>2:
# num.remove(value)
# nums[:]=num
# return(len(num)) # Do not allocate extra space for another array constarint
if len(nums)<=2:
return len(nums)
j=2
for i in range(2,len(sorted(nums))):
if nums[i]!=nums[j-2]: ## if current element is not same as
nums[j]=nums[i]
j+=1
return j

0 comments on commit 54fab29

Please sign in to comment.