-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH-Index.py
More file actions
32 lines (31 loc) · 723 Bytes
/
Copy pathH-Index.py
File metadata and controls
32 lines (31 loc) · 723 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
26
27
28
29
30
31
32
class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
citations.sort()
l = len(citations)
for i in range(l):
if citations[i] >= l - i:
return l - i
return 0
class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
l = len(citations)
count = [0] * (l + 1)
for c in citations:
if c > l:
count[l] += 1
else:
count[c] += 1
t = 0
for i in range(l, -1 , -1):
t += count[i]
if t >= i:
return i
return 0