-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIndex.py
More file actions
25 lines (23 loc) · 704 Bytes
/
HIndex.py
File metadata and controls
25 lines (23 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# https://leetcode.com/problems/h-index/
# #hash-table #sorting
class Solution:
# sort and binary search
def hIndex(self, citations: List[int]) -> int:
val = 0
size = len(citations)
if size == 0:
return val
# sort
citations.sort()
left = 1
right = citations[size - 1]
while(left <= right):
mid = left + (right - left) // 2
'Find leftmost item greater than or equal to mid'
i = bisect_left(citations, mid)
if size - i >= mid:
val = mid
left = mid + 1
else:
right = mid - 1
return val