Alexander Pantyukhin 0618d4d007
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>
2022-12-21 22:42:07 -06:00

22 lines
439 B
C

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