mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-22 21:43:08 +03:00

* 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>
22 lines
439 B
C
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;
|
|
}
|