Python simple solution


  • 0
    P
    class Solution(object):
        def hIndex(self, citations):
            """
            :type citations: List[int]
            :rtype: int
            """
            citations.sort(reverse = True)
            for i, num in enumerate( citations ):
                if num <= i+1:
                    return i+1 if num == i+1 else i
            else:
                return len(citations)
    

  • 0
    F

    @Phillf nicely done! One remark: you do not need the else statement after the for loop, just return outside of it. Cheers.


  • 0
    P

    @filet LOL, thanks for your advice!


Log in to reply
 

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