1984. 学生分数的最小差值
为保证权益,题目请参考 1984. 学生分数的最小差值(From LeetCode).
解决方案1
Python
python
# 1984. 学生分数的最小差值
# https://leetcode-cn.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores/
from typing import List
class Solution:
def minimumDifference(self, nums: List[int], k: int) -> int:
nums.sort()
minSub = 10000000
for i in range(len(nums) - k + 1):
if nums[i + k - 1] - nums[i] < minSub:
minSub = nums[i + k - 1] - nums[i]
return minSub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15