Leetcode-945 Minimum Increment to Make Array Unique(使数组唯一的最小增量)

 1 class Solution
 2 {
 3     public:
 4         int minIncrementForUnique(vector<int>& A)
 5         {
 6             int a[90000] {0};
 7             for(int i = 0;i < A.size();i ++)
 8                 a[A[i]] ++;
 9             
10             int result = 0;
11             for(int d = 0;d <= 89999;d ++)
12             {
13                 if(a[d]>=2)
14                 {
15                     result += a[d]-1;
16                     a[d+1] += a[d]-1;
17                 } 
18             }
19             return result;
20         }
21 };
原文地址:https://www.cnblogs.com/Asurudo/p/10016103.html