945. Minimum Increment to Make Array Unique Medium

@problem@discussion
#Array#Greedy#Sorting#Counting



1/**
2 * [945] Minimum Increment to Make Array Unique
3 *
4 * You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.
5 * Return the minimum number of moves to make every value in nums unique.
6 * The test cases are generated so that the answer fits in a 32-bit integer.
7 *  
8 * Example 1:
9 * 
10 * Input: nums = [1,2,2]
11 * Output: 1
12 * Explanation: After 1 move, the array could be [1, 2, 3].
13 * 
14 * Example 2:
15 * 
16 * Input: nums = [3,2,1,2,1,7]
17 * Output: 6
18 * Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
19 * It can be shown with 5 or less moves that it is impossible for the array to have all unique values.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= nums.length <= 10^5
25 * 	0 <= nums[i] <= 10^5
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/minimum-increment-to-make-array-unique/
31// discuss: https://leetcode.com/problems/minimum-increment-to-make-array-unique/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn min_increment_for_unique(nums: Vec<i32>) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_945() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.