LeetCode 274 H-Index

LeetCode 274 H-Index Problem

Download Code
class Solution(object):
    # def hIndex(self, citations):
    #     """
    #     :type citations: List[int]
    #     :rtype: int
    #     """
    #     # Sort and check the max h where the number of paper with no less than h citations
    #     # is no less than h
    #     citations.sort()
    #     ls = len(citations)
    #     h = ls
    #     while h > 0 and citations[ls - h] < h:
    #             h -= 1 
    #     return h

    # def hIndex(self, citations):
    #     citations.sort()
    #     i = 0
    #     while i < len(citations) and citations[len(citations) - 1 - i] > i:
    #         i += 1
    #     return i

    def hIndex(self, citations):
        # counting sort
        ls = len(citations)
        papers = [0] * (ls + 1)
        for c in citations:
            papers[min(ls, c)] += 1
        k, s = ls, papers[ls]
        while k > s:
            k -= 1
            s += papers[k]
        return k
Download H-Index.py

List of all H-Index problems

Leetcode 274 H-Index problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.