forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_1675.java
25 lines (23 loc) · 772 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
package com.fishercoder.solutions;
import java.util.TreeSet;
public class _1675 {
public static class Solution1 {
public int minimumDeviation(int[] nums) {
TreeSet<Integer> treeSet = new TreeSet<>();
for (int num : nums) {
if (num % 2 == 1) {
treeSet.add(num * 2);
} else {
treeSet.add(num);
}
}
int minDev = 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());
}
return minDev;
}
}
}