当前位置:网站首页>Daily question 1984 Minimum difference in student scores

Daily question 1984 Minimum difference in student scores

2022-07-05 05:42:00 A big pigeon

topic :

To give you one Subscript from 0 Start Array of integers for nums , among nums[i] It means the first one i A student's grade . I'll give you another integer k .

Select any... From the array k A student's grade , Make this k Between scores The highest and Lowest score Of Difference value achieve To minimize the .

Return possible Minimum difference  

Explain :

class Solution:
    def minimumDifference(self, nums: List[int], k: int) -> int:
        nums.sort()
        cc = [nums[i+k-1]-nums[i] for i in range(len(nums)-k+1)]
        return min(cc)

原网站

版权声明
本文为[A big pigeon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140620422265.html