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

Commit85430a3

Browse files
add 1984
1 parent3dedc14 commit85430a3

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1984|[Minimum Difference Between Highest and Lowest of K Scores](https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1984.java)||Easy||
1112
|1981|[Minimize the Difference Between Target and Chosen Elements](https://leetcode.com/problems/minimize-the-difference-between-target-and-chosen-elements/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1981.java)||Medium|DP|
1213
|1980|[Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1980.java)||Medium||
1314
|1979|[Find Greatest Common Divisor of Array](https://leetcode.com/problems/find-greatest-common-divisor-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1979.java)||Easy||
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1984 {
6+
publicstaticclassSolution1 {
7+
publicintminimumDifference(int[]nums,intk) {
8+
Arrays.sort(nums);
9+
intminDiff =nums[nums.length -1];
10+
for (inti =0;i <=nums.length -k;i++) {
11+
minDiff =Math.min(minDiff,nums[i +k -1] -nums[i]);
12+
}
13+
returnminDiff;
14+
}
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1984;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1984Test {
10+
privatestatic_1984.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1984.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(0,solution1.minimumDifference(newint[]{90},1));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(2,solution1.minimumDifference(newint[]{9,4,1,7},2));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp