smj007

h-index

Aug 31st, 2025
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. class Solution:
  2.     def hIndex(self, citations: List[int]) -> int:
  3.         citations.sort(reverse=True)
  4.  
  5.         h = 0
  6.         for index, c in enumerate(citations):
  7.             if c >= index + 1:
  8.                 h = index + 1
  9.             else:
  10.                 break
  11.  
  12.         return h
  13.  
  14. class Solution:
  15.     def hIndex(self, citations: List[int]) -> int:
  16.         n = len(citations)
  17.         counts = [0]*(n+1)
  18.  
  19.         # buckets the
  20.         for c in citations:
  21.             if c>=n:
  22.                 counts[n] += 1
  23.             else:
  24.                 counts[c] += 1
  25.  
  26.         total = 0
  27.         for i in range(n, -1, -1):
  28.             total += counts[i]
  29.             if total >= i:
  30.                 return i
  31.  
  32.         return 0
  33.  
Advertisement
Add Comment
Please, Sign In to add comment