当前位置:网站首页>Leetcode minimum difference in student scores
Leetcode minimum difference in student scores
2022-07-07 05:00:00 【kt1776133839】
Title Description :
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 .
Examples :
Example 1:
Input :nums = [90], k = 1
Output :0
explain : elect 1 A student's grade , have only 1 Methods :
- [90] The difference between the highest score and the lowest score is 90 - 90 = 0
The smallest possible difference is 0
Example 2:
Input :nums = [9,4,1,7], k = 2
Output :2
explain : elect 2 A student's grade , Yes 6 Methods :
- [9,4,1,7] The difference between the highest score and the lowest score is 9 - 4 = 5
- [9,4,1,7] The difference between the highest score and the lowest score is 9 - 1 = 8
- [9,4,1,7] The difference between the highest score and the lowest score is 9 - 7 = 2
- [9,4,1,7] The difference between the highest score and the lowest score is 4 - 1 = 3
- [9,4,1,7] The difference between the highest score and the lowest score is 7 - 4 = 3
- [9,4,1,7] The difference between the highest score and the lowest score is 7 - 1 = 6
The smallest possible difference is 2
Tips :
1 <= k <= nums.length <= 10000 <= nums[i] <= 105
Java Program :
class Solution {
public int minimumDifference(int[] nums, int k) {
Arrays.sort(nums);
int ans=nums[k-1]-nums[0];
for(int i=1;i<=nums.length-k;i++){ans=Math.min(ans,nums[i+k-1]-nums[i]);}
return ans;
}
}边栏推荐
- What work items do programmers hate most in their daily work?
- STM32 system timer flashing LED
- U++4 接口 学习笔记
- 接口间调用为什么要用json、fastjson怎么赋值的、fastjson [email protected]映射关系问题
- [digital analog] source code of MATLAB allcycles() function (not available before 2021a)
- If you‘re running pod install manually, make sure flutter pub get is executed first.
- Field data acquisition and edge calculation scheme of CNC machine tools
- Zhou Yajin, a top safety scholar of Zhejiang University, is a curiosity driven activist
- In depth analysis of kubebuilder
- Ansible中的inventory主機清單(預祝你我有數不盡的鮮花和浪漫)
猜你喜欢

动态生成表格

Ansible报错:“msg“: “Invalid/incorrect password: Permission denied, please try again.“

Markdown编辑器

Error: No named parameter with the name ‘foregroundColor‘

九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」

acwing 843. N-queen problem

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

Basic knowledge of road loss of 3GPP channel model

Markdown editor

Chapter 9 Yunji datacanvas company won the highest honor of the "fifth digital finance innovation competition"!
随机推荐
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
Analyse approfondie de kubebuilder
acwing 843. N-queen problem
使用Thread类和Runnable接口实现多线程的区别
A detailed explanation of head pose estimation [collect good articles]
Code source de la fonction [analogique numérique] MATLAB allcycles () (non disponible avant 2021a)
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
谈谈讲清楚这件事的重要性
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
Pointer and array are input in function to realize reverse order output
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
程序员上班摸鱼,这么玩才高端!
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.
What is JVM? What are the purposes of JVM tuning?
JS variable
【736. Lisp 语法解析】
关于01背包个人的一些理解
01 machine learning related regulations
Gpt-3 is a peer review online when it has been submitted for its own research
Field data acquisition and edge calculation scheme of CNC machine tools