java.lang.Object
g0901_1000.s0945_minimum_increment_to_make_array_unique.Solution

public class Solution extends Object
945 - Minimum Increment to Make Array Unique.<p>Medium</p> <p>You are given an integer array <code>nums</code>. In one move, you can pick an index <code>i</code> where <code>0 <= i < nums.length</code> and increment <code>nums[i]</code> by <code>1</code>.</p> <p>Return <em>the minimum number of moves to make every value in</em> <code>nums</code> <em><strong>unique</strong></em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,2]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> After 1 move, the array could be [1, 2, 3].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3,2,1,2,1,7]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> After 6 moves, the array could be [3, 4, 1, 2, 5, 7]. It can be shown with 5 or less moves that it is impossible for the array to have all unique values.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>0 <= nums[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minIncrementForUnique

      public int minIncrementForUnique(int[] nums)