Python solution


  • 0
    H
    class Solution(object):
        def hIndex(self, citations):
            """
            :type citations: List[int]
            :rtype: int
            """
            #citations=sorted(citations)
            hi=[0]*(len(citations)+1)
            eq=list(hi)+[0]
            for c in citations:
                if c < len(eq):
                    eq[c]+=1
                else:
                    eq[-1]+=1
            hi[-1]=eq[-1]+eq[-2]
            for i in xrange(len(hi)-2,-1,-1):
                hi[i]=hi[i+1]+eq[i]
            h=0
            for i in xrange(len(hi)):
                if hi[i]-eq[i]<=i<=hi[i]:
                    h=i
            return h

Log in to reply
 

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