Skip to content

Commit e04257b

Browse files
add 2357
1 parent 304ba8f commit e04257b

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11-
| 2352 |[Equal Row and Column Pairs](https://leetcode.com/problems/equal-row-and-column-pairs/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2352.java) || Medium ||
11+
| 2357 |[Make Array Zero by Subtracting Equal Amounts](https://leetcode.com/problems/make-array-zero-by-subtracting-equal-amounts/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2357.java) || Easy ||
12+
| 2352 |[Equal Row and Column Pairs](https://leetcode.com/problems/equal-row-and-column-pairs/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2352.java) || Medium ||
1213
| 2351 |[First Letter to Appear Twice](https://leetcode.com/problems/first-letter-to-appear-twice/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2351.java) || Easy ||
1314
| 2347 |[Maximum Number of Pairs in Array](https://leetcode.com/problems/best-poker-hand/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2347.java) || Easy ||
1415
| 2341 |[Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2341.java) || Easy ||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.TreeSet;
4+
5+
public class _2357 {
6+
public static class Solution1 {
7+
public int minimumOperations(int[] nums) {
8+
TreeSet<Integer> treeSet = new TreeSet<>();
9+
for (int num : nums) {
10+
if (num > 0) {
11+
treeSet.add(num);
12+
}
13+
}
14+
int ops = 0;
15+
while (!treeSet.isEmpty()) {
16+
int min = treeSet.pollFirst();
17+
ops++;
18+
TreeSet<Integer> tmp = new TreeSet<>();
19+
while (!treeSet.isEmpty()) {
20+
tmp.add(treeSet.pollFirst() - min);
21+
}
22+
treeSet.addAll(tmp);
23+
}
24+
return ops;
25+
}
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2357;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2357Test {
10+
private static _2357.Solution1 solution1;
11+
private static int[] nums;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _2357.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
nums = new int[]{1, 5, 0, 3, 5};
21+
assertEquals(3, solution1.minimumOperations(nums));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)