- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1675.java
25 lines (23 loc) · 787 Bytes
/
_1675.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.TreeSet;
publicclass_1675 {
publicstaticclassSolution1 {
publicintminimumDeviation(int[] nums) {
TreeSet<Integer> treeSet = newTreeSet<>();
for (intnum : nums) {
if (num % 2 == 1) {
treeSet.add(num * 2);
} else {
treeSet.add(num);
}
}
intminDev = treeSet.last() - treeSet.first();
while (treeSet.last() % 2 == 0) {
treeSet.add(treeSet.last() / 2);
treeSet.remove(treeSet.last());
minDev = Math.min(minDev, treeSet.last() - treeSet.first());
}
returnminDev;
}
}
}