Skip to content

Commit 4f55c1e

Browse files
committed
Add Java solution 1984-minimum-difference-between-highest-and-lowest-of-k-scores.java
1 parent 61450be commit 4f55c1e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int minimumDifference(int[] nums, int k) {
3+
if(k == 1) return 0;
4+
5+
Arrays.sort(nums);
6+
7+
int min = Integer.MAX_VALUE;
8+
for(int i=0; i<nums.length-k+1; i++) {
9+
int diff = Math.abs(nums[i] - nums[i+k-1]);
10+
min = Math.min(diff, min);
11+
}
12+
13+
return min;
14+
}
15+
}

0 commit comments

Comments
 (0)