9/20/2020

[LeetCode] 275. H-Index II

 Problem : https://leetcode.com/problems/h-index-ii/


class Solution:
    def hIndex(self, citations: List[int]) -> int:
        N = len(citations)
        left, right = 0, N - 1
        
        while left <= right:
            mid = left + (right - left) // 2    
            h = N - mid
                        
            if citations[mid] == h:
                return h
            
            if citations[mid] < h:
                left = mid + 1
            else:
                right = mid - 1
        
        return N - left

No comments:

Post a Comment