Skip to content

Commit 1ea298c

Browse files
add 945
1 parent 55885f5 commit 1ea298c

File tree

3 files changed

+44
-0
lines changed
  • paginated_contents/algorithms/1st_thousand
  • src
    • main/java/com/fishercoder/solutions/firstthousand
    • test/java/com/fishercoder/firstthousand

3 files changed

+44
-0
lines changed

Diff for: paginated_contents/algorithms/1st_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
| 951 | [Flip Equivalent Binary Trees](https://leetcode.com/problems/flip-equivalent-binary-trees/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_951.java) | | Medium | Tree, DFS, recursion |
2929
| 950 | [Reveal Cards In Increasing Order](https://leetcode.com/problems/reveal-cards-in-increasing-order/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_950.java) | | Medium |
3030
| 946 | [Validate Stack Sequences](https://leetcode.com/problems/validate-stack-sequences/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_946.java) | | Medium | Stack
31+
| 945 | [Minimum Increment to Make Array Unique](https://leetcode.com/problems/minimum-increment-to-make-array-unique/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_945.java) | | Medium | Greedy
3132
| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_944.java) | | Easy |
3233
| 942 | [DI String Match](https://leetcode.com/problems/di-string-match/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_942.java) | | Easy |
3334
| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_941.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions.firstthousand;
2+
3+
import java.util.Arrays;
4+
5+
public class _945 {
6+
public static class Solution1 {
7+
public int minIncrementForUnique(int[] nums) {
8+
Arrays.sort(nums);
9+
int minIncs = 0;
10+
for (int i = 0; i < nums.length - 1; i++) {
11+
if (nums[i + 1] <= nums[i]) {
12+
minIncs += nums[i] - nums[i + 1] + 1;
13+
nums[i + 1] = nums[i] + 1;
14+
}
15+
}
16+
return minIncs;
17+
}
18+
}
19+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.firstthousand;
2+
3+
import com.fishercoder.solutions.firstthousand._945;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _945Test {
10+
private static _945.Solution1 solution1;
11+
private static int[] nums;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _945.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
nums = new int[]{3, 2, 1, 2, 1, 7};
21+
assertEquals(6, solution1.minIncrementForUnique(nums));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)