当前位置:网站首页>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;
}
}边栏推荐
- You can't sell the used lithography machine to China! The United States unreasonably pressured the Dutch ASML, and domestic chips were suppressed again
- Markdown editor
- Basic idea of counting and sorting
- 如何设计 API 接口,实现统一格式返回?
- Thesis landing strategy | how to get started quickly in academic thesis writing
- Function pointer and pointer function in C language
- A line of R code draws the population pyramid
- System framework of PureMVC
- Field data acquisition and edge calculation scheme of CNC machine tools
- Ansible报错:“msg“: “Invalid/incorrect password: Permission denied, please try again.“
猜你喜欢

U++ 元数据说明符 学习笔记

当 Knative 遇见 WebAssembly

【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
![[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet](/img/58/4337f0972f7171a5c21e640f03e0b7.png)
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet

A line of R code draws the population pyramid

计数排序基础思路
![[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III](/img/13/d598bb53b71fbadd4a97c603152124.png)
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III

Analyse approfondie de kubebuilder

namespace基础介绍

MySQL数据库(基础篇)
随机推荐
Ansible reports an error: "MSG": "invalid/incorrect password: permission denied, please try again“
Web3 社区中使用的术语
一文搞懂常见的网络I/O模型
What work items do programmers hate most in their daily work?
Function pointer and pointer function in C language
What is JVM? What are the purposes of JVM tuning?
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
窗口可不是什么便宜的东西
树与图的深度优先遍历模版原理
Windows are not cheap things
Comparison between thread and runnable in creating threads
R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
npm ERR! 400 Bad Request - PUT xxx - “devDependencies“ dep “xx“ is not a valid dependency name
A simple and beautiful regression table is produced in one line of code~
offer如何选择该考虑哪些因素
深入解析Kubebuilder
Two methods of chromosome coordinate sequencing
PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
leetcode 53. Maximum subarray maximum subarray sum (medium)
Operand of null-aware operation ‘!‘ has type ‘SchedulerBinding‘ which excludes null.