forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2357.java
27 lines (25 loc) · 767 Bytes
/
_2357.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.fishercoder.solutions;
import java.util.TreeSet;
public class _2357 {
public static class Solution1 {
public int minimumOperations(int[] nums) {
TreeSet<Integer> treeSet = new TreeSet<>();
for (int num : nums) {
if (num > 0) {
treeSet.add(num);
}
}
int ops = 0;
while (!treeSet.isEmpty()) {
int min = treeSet.pollFirst();
ops++;
TreeSet<Integer> tmp = new TreeSet<>();
while (!treeSet.isEmpty()) {
tmp.add(treeSet.pollFirst() - min);
}
treeSet.addAll(tmp);
}
return ops;
}
}
}