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 , 549 阅读

https://leetcode.com/problems/minimum-increment-to-make-array-unique/

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
    }
    sort.Ints(A)
    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.

Aaple Sarkar Portal 说:
Nov 05, 2022 05:09:51 PM

A comprehensive website portal is pretty significant to all citizens. It eases the need to visit several government offices for services. The Maharashtra state government has designed an inclusive website portal to accommodate all government services and incentives. All relevant department details are easily accessible on the page. Aaple Sarkar Portal Online Registration 2023 Maharashtra residents can avail the income certificate and other services from the website without visit any office.

बोर्ड-हिंदी-प्रश्नपत 说:
May 01, 2023 03:30:26 PM

Hindi Model Question Papers Bihar School 10th Exam Board BSEB, Bihar Board 10th Class Model Papers 2023 Matric Exam Pattern, BSEB Patna Board Matric 10th Model Papers 2023 Sample Questions, Bihar Board 10th Model Papers 2023 Download, बोर्ड-हिंदी-प्रश्नपत्र.com BSEB Matric Bihar matric model paper 2023 bseb 10th sample paper 2023, bihar board 10th model paper 2023 pdf, bihar board 10th class model test paper 2023, bseb matric previous sample paper class 10th bihar board model question paper, bseb matric model question paper 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter