Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 896 Bytes

File metadata and controls

46 lines (33 loc) · 896 Bytes

945. Question 945

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 : N/A

Acceptance Rate : Unknown


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