Skip to content

Commit 0b3d11c

Browse files
[LEET-3396] add 3396
1 parent fec696f commit 0b3d11c

File tree

2 files changed

+35
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

2 files changed

+35
-0
lines changed

paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3396 |[Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java)|| Easy |
34
| 3370 |[Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java)|| Easy |
45
| 3364 |[Minimum Positive Sum Subarray](https://leetcode.com/problems/minimum-positive-sum-subarray/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3364.java)|| Easy |
56
| 3360 |[Stone Removal Game](https://leetcode.com/problems/stone-removal-game/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3360.java)|| Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
6+
publicclass_3396 {
7+
publicstaticclassSolution1 {
8+
publicintminimumOperations(int[] nums) {
9+
intops = 0;
10+
Map<Integer, Integer> map = newHashMap<>();
11+
for (intnum : nums) {
12+
map.put(num, map.getOrDefault(num, 0) + 1);
13+
}
14+
inti = 0;
15+
while (!allDistinct(map)) {
16+
ops++;
17+
inttarget = i + 3;
18+
for (; i < target && i < nums.length; i++) {
19+
map.put(nums[i], map.get(nums[i]) - 1);
20+
}
21+
}
22+
returnops;
23+
}
24+
25+
privatebooleanallDistinct(Map<Integer, Integer> map) {
26+
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
27+
if (entry.getValue() > 1) {
28+
returnfalse;
29+
}
30+
}
31+
returntrue;
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)
close