POC (Piece of Cake) 4ms


  • 0
    0
    int comp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
    int max(int a, int b) { return a > b ? a : b; }
    int min(int a, int b) { return a < b ? a : b; }
    
    int hIndex(int* citations, int citationsSize) {
        qsort(citations, citationsSize, sizeof(int), comp);
        int result = 0;
        int i;
        for (i = citationsSize - 1; i >= 0; --i)
            result = max(result, min(citationsSize - i, citations[i]));
        return result;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.