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

Commit13c62b7

Browse files
[LEET-3375] ADD 3375
1 parentf3e7703 commit13c62b7

File tree

3 files changed

+53
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+53
-0
lines changed

‎paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
33
| 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|
44
| 3392|[Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java)|| Easy|
5+
| 3375|[Minimum Operations to Make Array Values Equal to K](https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3375.java)|| Easy|
56
| 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|
67
| 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|
78
| 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.TreeMap;
4+
5+
publicclass_3375 {
6+
publicstaticclassSolution1 {
7+
publicintminOperations(int[]nums,intk) {
8+
TreeMap<Integer,Integer>map =newTreeMap<>();
9+
for (intnum :nums) {
10+
map.put(num,map.getOrDefault(num,0) +1);
11+
}
12+
if (map.firstKey() <k) {
13+
return -1;
14+
}
15+
if (map.firstKey() ==k) {
16+
returnmap.size() -1;
17+
}
18+
returnmap.size();
19+
}
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.fishercoder.fourththousand;
2+
3+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
4+
5+
importcom.fishercoder.solutions.fourththousand._3375;
6+
importorg.junit.jupiter.api.BeforeEach;
7+
importorg.junit.jupiter.api.Test;
8+
9+
publicclass_3375Test {
10+
private_3375.Solution1solution1;
11+
12+
@BeforeEach
13+
publicvoidsetup() {
14+
solution1 =new_3375.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(2,solution1.minOperations(newint[] {5,2,5,4,5},2));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(-1,solution1.minOperations(newint[] {2,1,2},2));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(4,solution1.minOperations(newint[] {9,7,5,3},1));
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp