working, needs refinement on multiple hits
This commit is contained in:
parent
9361e527c3
commit
2bb5fc48da
@ -3,26 +3,38 @@ def hIndex(citations):
|
|||||||
:type citations: List[int]
|
:type citations: List[int]
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
citations.sort()
|
h = 0
|
||||||
h = citations[0]
|
|
||||||
count = 0
|
|
||||||
newH = 0
|
|
||||||
if len(citations) == 1:
|
if len(citations) == 1:
|
||||||
if citations[0] == 0:
|
if citations[0] == 0:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
for x in range(len(citations)):
|
for x in range(len(citations)):
|
||||||
if h == citations[x]:
|
count = 0
|
||||||
newH = citations[x]
|
for i in range(x,len(citations)):
|
||||||
elif citations[x] > h and newH == 0:
|
print((f'x is {citations[x]}'))
|
||||||
newH = citations[x]
|
print((f'i is {citations[i]}'))
|
||||||
# print(newH)
|
if citations[x] <= citations[i] and citations[x] != 0:
|
||||||
print(newH)
|
print('hit')
|
||||||
return newH
|
count += 1
|
||||||
|
if count >= citations[x] and citations[x] != 0:
|
||||||
|
# print(citations[x])
|
||||||
|
if citations[x] >= h:
|
||||||
|
h = citations[x]
|
||||||
|
# print(h)
|
||||||
|
elif citations[x] > count and citations[x] != 0 and x+1 == len(citations)-1:
|
||||||
|
if citations[x] >= h:
|
||||||
|
h = count
|
||||||
|
# print(h)
|
||||||
|
# print(f'final: {h}')
|
||||||
|
# return h
|
||||||
|
|
||||||
hIndex([3,0,6,1,5]) # 3
|
# hIndex([3,0,6,1,5]) # 3
|
||||||
# hIndex([1,3,1]) # 1
|
# hIndex([1,3,1]) # 1
|
||||||
# hIndex([0,1]) # 1
|
# hIndex([0,1]) # 1
|
||||||
|
# hIndex([0,0]) # 1
|
||||||
# hIndex([1,2]) # 1
|
# hIndex([1,2]) # 1
|
||||||
# hIndex([2,1]) # 1
|
# hIndex([2,1]) # 1
|
||||||
|
# hIndex([11,15]) # 2
|
||||||
|
# hIndex([1,2,2]) # 2
|
||||||
|
hIndex([2,3,2]) # 2
|
||||||
Loading…
Reference in New Issue
Block a user