Skip to content

Instantly share code, notes, and snippets.

@jan25
Last active June 18, 2020 12:16
Show Gist options
  • Save jan25/ff5bfd60a0dbf5c715cd2911c0692252 to your computer and use it in GitHub Desktop.
Save jan25/ff5bfd60a0dbf5c715cd2911c0692252 to your computer and use it in GitHub Desktop.
researcher.py
class Solution:
def hIndex(self, citations: List[int]) -> int:
cnt = defaultdict(int)
h, nGreaterThanH = 0, 0
for c in citations:
# Count elements greater than current h
if c > h:
cnt[c] += 1
nGreaterThanH += 1
# if we have more greater elements than h
# increase h and adjust num of elements greater than h
if nGreaterThanH == h + 1:
h += 1
# cnt[h] represent elements equaling h
# minus, because we want to count element greater than h
nGreaterThanH = h - cnt[h]
return h
@jskrnbindra
Copy link

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment