Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b20425

Browse files
add 1675
1 parentf35afca commit3b20425

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.TreeSet;
4+
5+
publicclass_1675 {
6+
publicstaticclassSolution1 {
7+
publicintminimumDeviation(int[]nums) {
8+
TreeSet<Integer>treeSet =newTreeSet<>();
9+
for (intnum :nums) {
10+
if (num %2 ==1) {
11+
treeSet.add(num *2);
12+
}else {
13+
treeSet.add(num);
14+
}
15+
}
16+
intminDev =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+
returnminDev;
23+
}
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1675;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1675Test {
10+
privatestatic_1675.Solution1solution1;
11+
privatestaticint[]nums;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_1675.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(1,solution1.minimumDeviation(newint[]{1,2,3,4}));
21+
}
22+
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp