美文网首页
274. H-Index

274. H-Index

作者: April63 | 来源:发表于2018-06-14 20:48 被阅读0次

笨方法,写完就睡着了

class Solution(object):
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        if len(citations) == 0:
            return 0
        lenth = len(citations)
        h = lenth
        while h > 0:
            if self.count(citations, h) >= h:
                return h
            h -= 1
        return 0
    def count(self, citetions, h):
        count = 0
        for c in citetions:
            if c >= h:
                count += 1
        return count
        

如果是排好序就很容易了,代码如下:

class Solution:
    def hIndex(self, citations):
        citations.sort()
        for i in range(len(citations)):
            if len(citations) - i <= citations[i]: return len(citations) - i
        return 0

相关文章

  • 2019-02-05

    LeetCode 274. H-Index Description Given an array of citat...

  • ARTS 第22周

    ARTS 第22周分享 [TOC] Algorithm 274. H-Index [medium] [题目描述] ...

  • 274. H-Index

    笨方法,写完就睡着了 如果是排好序就很容易了,代码如下:

  • 274. H-Index

    Question Given an array of citations (each citation is a ...

  • 274. H-Index

    Given an array of citations (each citation is a non-negat...

  • 274. H-Index

    问题 Given an array of citations (each citation is a non-ne...

  • 274. H-Index

  • 274. H-Index

    问题描述 Given an array of citations (each citation is a non-...

  • 274. H-Index, 275. H-Index II

    274 就先sort一下,再遍历一遍从高到低排序,然后从左向右扫。如果一个数的值大于等于他的index + 1,则...

  • Leetcode解题报告——274. H-Index

    题目要求:Given an array of citations (each citation is a non-...

网友评论

      本文标题:274. H-Index

      本文链接:https://www.haomeiwen.com/subject/ugkueftx.html