Skip to content

Commit 3b20425

Browse files
add 1675
1 parent f35afca commit 3b20425

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ _If you like this project, please leave me a star._ ★
3131
|1680|[Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1680.java) ||Medium|Math|
3232
|1679|[Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1679.java) ||Medium|HashTable|
3333
|1678|[Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1678.java) ||Easy|String|
34+
|1675|[Minimize Deviation in Array](https://leetcode.com/problems/minimize-deviation-in-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1675.java) ||Hard|Heap, Ordered Map|
3435
|1673|[Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1673.java) ||Medium|Stack, Greedy|
3536
|1672|[Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1672.java) ||Easy|Array|
3637
|1669|[Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1669.java) ||Medium|LinedList|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.TreeSet;
4+
5+
public class _1675 {
6+
public static class Solution1 {
7+
public int minimumDeviation(int[] nums) {
8+
TreeSet<Integer> treeSet = new TreeSet<>();
9+
for (int num : nums) {
10+
if (num % 2 == 1) {
11+
treeSet.add(num * 2);
12+
} else {
13+
treeSet.add(num);
14+
}
15+
}
16+
int minDev = treeSet.last() - treeSet.first();
17+
while (treeSet.last() % 2 == 0) {
18+
treeSet.add(treeSet.last() / 2);
19+
treeSet.remove(treeSet.last());
20+
minDev = Math.min(minDev, treeSet.last() - treeSet.first());
21+
}
22+
return minDev;
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1675;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1675Test {
10+
private static _1675.Solution1 solution1;
11+
private static int[] nums;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1675.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertEquals(1, solution1.minimumDeviation(new int[]{1, 2, 3, 4}));
21+
}
22+
23+
}

0 commit comments

Comments
 (0)