275. H-Index II
O(n)
class Solution:
def hIndex(self, citations: List[int]) -> int:
res = 0
for index in range(len(citations)):
if citations[len(citations)-1-index] >= index + 1:
res = index + 1
return res
O(logn)
class Solution:
def hIndex(self, citations: List[int]) -> int:
res = 0
length = len(citations)
lo, hi = 0, length
while lo < hi:
mid = lo + (hi - lo) // 2
if citations[length-1-mid] >= mid + 1:
lo = mid+1
else:
hi = mid
return lo
274. H-Index
class Solution:
def hIndex(self, citations: List[int]) -> int:
citations.sort()
length = len(citations)
lo, hi = 0, length
while lo < hi:
mid = lo + (hi - lo) // 2
if citations[length-1-mid] >= mid + 1:
lo = mid+1
else:
hi = mid
return lo