Python simple binary search


  • 0
    A
    class Solution(object):
        def hIndex(self, citations):
            """
            :type citations: List[int]
            :rtype: int
            """
            l=0
            r=len(citations)
            
            while l<r:
                
                m = (l+r)/2
                if len(citations[m:])<=citations[m]:
                    r=m
                else:
                    l=m+1        
            
            return len(citations[l:])
            
    

Log in to reply
 

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