class Solution:
def hIndex(self, citations: List[int]) -> int:
if not citations or len(citations)==0: return 0
n = len(citations)
l, r = 0, n-1
while(l+1<r):
mid = l+int((r-l)/2)
if n-mid <= citations[mid]: r=mid
else: l=mid
if not l and n-l<=citations[l]: return n
if r==n-1 and n-r>citations[r]: return 0
if n-r<=citations[r]: return n-r
else: return n-l