We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a7cba97 commit 3a62a06Copy full SHA for 3a62a06
src/task_1675/Solution.java
@@ -0,0 +1,33 @@
1
+package task_1675;
2
+
3
+import java.util.TreeSet;
4
5
+public class Solution {
6
7
+ public int minimumDeviation(int[] nums) {
8
+ TreeSet<Integer> set = new TreeSet<>();
9
+ for (int i = 0; i < nums.length; i++) {
10
+ if (nums[i] % 2 == 0) {
11
+ set.add(nums[i]);
12
+ } else {
13
+ set.add(nums[i] * 2);
14
+ }
15
16
+ int max = Integer.MIN_VALUE;
17
+ int min = Integer.MAX_VALUE;
18
+ int minDiff = Integer.MAX_VALUE;
19
+ while (true) {
20
+ max = set.last();
21
+ min = set.first();
22
+ minDiff = Math.min(minDiff, max - min);
23
+ if (max % 2 == 0) {
24
+ set.remove(max);
25
+ set.add(max / 2);
26
27
+ break;
28
29
30
+ return minDiff;
31
32
33
+}
0 commit comments