-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhIndex.py
More file actions
21 lines (20 loc) · 762 Bytes
/
hIndex.py
File metadata and controls
21 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution:
def hIndex(self, citations):
#citations.sort()
papers = len(citations)
#create an array filled with zeros
bucketCita = [0] * (papers + 1)
#two loops one for see citations in buckets
for citation in citations:
bucketCita[min(citation, papers)] += 1
#another for loop to find the h-index
#indices are number of citations in bucketCita
cumu_papers = 0
#for bIndex in bucketCita[::-1]:
for hIndex in range(papers, -1,-1):
#see how we pass hIndex to bucketCita below
cumu_papers += bucketCita[hIndex]
if cumu_papers >= hIndex:
return hIndex
myVar = Solution()
myVar.hIndex([3,0,6,1,5])