Problem : https://leetcode.com/problems/h-index/
Sort citations in ascending order.
Iterate from the first item. If value of current item > = number of remaining items (includes current item). Return the number of remaining items as H-index.
class Solution:
def hIndex(self, citations: List[int]) -> int:
citations.sort()
N = len(citations)
for i in range(N):
# N - i = number of remaining paper
if citations[i] >= N - i:
return N - i
return 0
No comments:
Post a Comment