Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b3d11c

Browse files
[LEET-3396] add 3396
1 parentfec696f commit0b3d11c

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

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 34 additions & 0 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp