mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
feat: add H-Index LeetCode problem (#1188)
* add leetcode H-Index * Update leetcode/src/274.c Co-authored-by: Taj <tjgurwara99@users.noreply.github.com> * Update 274.c fix review notes. Co-authored-by: David Leal <halfpacho@gmail.com> Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
This commit is contained in:
parent
cafd06725c
commit
0618d4d007
@ -69,6 +69,7 @@
|
||||
| 236 | [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) | [C](./src/236.c) | Medium |
|
||||
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | [C](./src/242.c) | Easy |
|
||||
| 268 | [Missing Number](https://leetcode.com/problems/missing-number/) | [C](./src/268.c) | Easy |
|
||||
| 274 | [H-Index](https://leetcode.com/problems/h-index/description/) | [C](./src/274.c) | Medium |
|
||||
| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version/) | [C](./src/278.c) | Easy |
|
||||
| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes/) | [C](./src/283.c) | Easy |
|
||||
| 287 | [Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | [C](./src/287.c) | Medium |
|
||||
|
21
leetcode/src/274.c
Normal file
21
leetcode/src/274.c
Normal file
@ -0,0 +1,21 @@
|
||||
int diff(const int* i, const int* j)
|
||||
|
||||
{
|
||||
return *i - *j;
|
||||
}
|
||||
|
||||
|
||||
// Sorting.
|
||||
// Runtime: O(n*log(n))
|
||||
// Space: O(1)
|
||||
int hIndex(int* citations, int citationsSize){
|
||||
qsort(citations, citationsSize, sizeof(int), (int(*) (const void*, const void*)) diff);
|
||||
|
||||
for(int i = 0; i < citationsSize; i++){
|
||||
if (citations[citationsSize - 1 - i] <= i){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return citationsSize;
|
||||
}
|
Loading…
Reference in New Issue
Block a user