Skip to content

Commit

Permalink
leetcode min ops to make array distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatelmas committed Jan 2, 2025
1 parent 4b0559c commit 3770d4a
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List


class Solution:
def minimumOperations(self, nums: List[int]) -> int:
l, s, k = len(nums), set(), -1
for i in range(l - 1, -1, -1):
if nums[i] in s:
k = i
break
s.add(nums[i])

n, m = divmod(k + 1, 3)
if m:
n += 1
return n

0 comments on commit 3770d4a

Please sign in to comment.