H-Index

Problem: H-Index

We just sort the citations in descending order and start guessing h-index from a small citation number and a bigger h number.

Code in Python:

class Solution(object):
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        citations = sorted(citations)[::-1]
        n = len(citations)
        for i in xrange(n-1, -1, -1):
            if citations[i] >= i+1: return i+1
        return 0

results matching ""

    No results matching ""