O(n) Using Python


  • 0
    from collections import defaultdict
    
    class Solution(object):
        def hIndex(self, citations):
            n = len(citations)
            dic = defaultdict(int)
            for citation in citations:
                if citation < n:
                    dic[citation] += 1
                else:
                    dic[n] += 1
            accum = 0
            for i in range(n, 0, -1):
                accum += dic[i]
                if accum >= i:
                    return i
            return 0
            
    

Log in to reply
 

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