According to the formula, easy to solve this problem

• ``````def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
return max(map(min, enumerate(sorted(citations, reverse=True), 1))) if citations else 0``````

• One line solution

``````class Solution(object):
def hIndex(self, citations):
return sum(1 if x >= i + 1 else 0 for i, x in enumerate(sorted(citations, reverse=True)))``````

• This code may be shortened if you like :-)

``````class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
return max(map(min, enumerate(sorted(citations, reverse=True), 1))) if citations else 0 ``````

• Nice one-line code using `sum` :-)

• I like clean code, thank you for cleanning it

• another good idea

• This post is deleted!

• Just a bit shorter:

``````def hIndex(self, citations):
return max(map(min, enumerate(sorted(citations)[::-1], 1)) + [0])
``````

• Great, Stefan! Nice `[::-1]` and `+ [0]` :-)

• can someone explain why this formula works?

• Hi, kilimchoi. You may refer to the wikipedia page on H-Index for some explanations. The formula is just taken from there.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.