Leetcode - Unique Email Addresses
Leetcode - Top K Frequent Elements

Leetcode - Minimum Increment to Make Array Unique

violet posted @ Jul 15, 2020 06:51:25 AM in 算法 with tags Algorithm Golang array , 314 阅读


Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1.

Return the least number of moves to make every value in A unique.


Example 1:

Input: [1,2,2]
Output: 1
Explanation:  After 1 move, the array could be [1, 2, 3].

Example 2:

Input: [3,2,1,2,1,7]
Output: 6
Explanation:  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.


func minIncrementForUnique(A []int) int {
    if len(A) < 2 {
        return 0
    result := 0
    for i := 1; i < len(A); i++ {
        if A[i] <= A[i-1] {
            result += A[i-1] + 1 - A[i]
            A[i] = A[i-1] + 1
    return result
Delhi Escort 说:
Jun 28, 2021 11:25:56 AM

I am glad that I found this post, it was amazing. I will surely read all the other posts on this site. and I also want to know how can I share my written blogs on this website?

CIBIL customer care 说:
Aug 06, 2022 10:24:46 PM

While for customers, they provide a score and credit report which identifies customers about their present credit lifestyle. CIBIL helps to make better monetary adjustments allowing them to be able to apply for loans, credit services and more. It is true that CIBIL is one of the largest credit insights aggregators. Sometimes there are some issues as well that CIBIL customers would face. In those situations, CIBIL customer care those customers need not worry because the beware has already created with dedicated CIBIL customer care.This is an essential service ready to serve and help you with your questions, issues, complaints, and more that come along their way. In this article, we will provide you a piece of brief information about the different ways a user can reach out to CIBIL customer care for help regarding their query, and issues to resolve.

登录 *

loading captcha image...
or Ctrl+Enter