class Solution {
public int minimumDifference(int[] nums, int k) {
Arrays.sort(nums);
int n = nums.length;
int ans = Integer.MAX_VALUE;
for(int i = 0; i + k - 1 < n;i++) {
ans = Math.min(ans, nums[i + k - 1] - nums[i]);
}
return ans;
}
}
Leetcode_1984_学生分数最小值
最新推荐文章于 2022-11-22 10:45:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)