Python. O(nlogn) (using sort)


  • 0
    P
    class Solution(object):
        def hIndex(self, citations):
            """
            :type citations: List[int]
            :rtype: int
            """
            #sorted builtin takes nlogn time
            citations=sorted(citations)
            length=len(citations)
            i=0
            while i<length:
                if citations[i]>=len(citations)-i:
                    return len(citations)-i
                i+=1
            return 0

Log in to reply
 

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