Last active
June 18, 2020 12:16
-
-
Save jan25/ff5bfd60a0dbf5c715cd2911c0692252 to your computer and use it in GitHub Desktop.
researcher.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🎉