Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.1 KB

_945. Minimum Increment to Make Array Unique.md

File metadata and controls

46 lines (33 loc) · 1.1 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 14, 2024

Last updated : July 01, 2024


Related Topics : Array, Greedy, Sorting, Counting

Acceptance Rate : 60.09 %


Solutions

Python

class Solution:
    def minIncrementForUnique(self, nums: List[int]) -> int:
        nums.sort()

        prevVals = set()
        maxVal = -inf
        output = 0
        for num in nums :
            if num in prevVals :
                maxVal = maxVal + 1
                output += maxVal - num
                prevVals.add(maxVal)
            else :
                maxVal = num
                prevVals.add(num)

        return output