Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fd3899c

Browse files
authored
Create Minimum Increment to Make Array Unique.java
1 parent 27aee48 commit fd3899c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int minIncrementForUnique(int[] nums) {
3+
Arrays.sort(nums);
4+
int increments = 0;
5+
for (int i = 1; i < nums.length; i++) {
6+
if (nums[i] <= nums[i - 1]) {
7+
increments += nums[i - 1] + 1 - nums[i];
8+
nums[i] = nums[i - 1] + 1;
9+
}
10+
}
11+
return increments;
12+
}
13+
}

0 commit comments

Comments
 (0)