Skip to content

Commit 8ee1c93

Browse files
committed
Added 1984-minimum-difference-between-highest-and-lowest-of-k-scores.c
1 parent 40fc3e8 commit 8ee1c93

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
int cmp(const void* a, const void* b) {
2+
return *(int*)a - *(int*)b;
3+
}
4+
5+
int min(int a, int b){
6+
if(a > b) return b;
7+
return a;
8+
}
9+
10+
int minimumDifference(int* nums, int numsSize, int k) {
11+
if (k == 1) return 0;
12+
13+
qsort(nums, numsSize, sizeof(int), cmp);
14+
int res = 1e5;
15+
int l = 0;
16+
int r = k - 1;
17+
18+
while (r < numsSize)
19+
{
20+
res = min(res, nums[r] - nums[l]);
21+
l += 1;
22+
r += 1;
23+
}
24+
25+
return res;
26+
}

0 commit comments

Comments
 (0)