Remove Duplicates from Sorted Array (Leetcode 26)
Problem Link: https://leetcode.com/problems/remove-duplicates-from-sorted-array/
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
# Do not return anything
n=len(nums)
ans=[]
i=0
j=0
while(j<n):
while(j<n and nums[j]==nums[i]):
j+=1
if(j==n):
ans.append(nums[i])
break
else:
ans.append(nums[i])
i=j
nums[:]=ans
PreviousFind the Duplicate Number (Leetcode 287)NextPairs of Songs With Total Durations Divisible by 60 (Leetcode 1010)
Last updated