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:
Alexander Pantyukhin 2022-12-22 08:42:07 +04:00 committed by GitHub
parent cafd06725c
commit 0618d4d007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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
View 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;
}