美文网首页
8.27 - hard - 110

8.27 - hard - 110

作者: 健时总向乱中忙 | 来源:发表于2017-08-28 09:28 被阅读0次

630. Course Schedule III

现排序,再用heap,很多greedy的问题都可以这样来做。基本上就是排序,或者是heap,或者两者合用。

class Solution(object):
    def scheduleCourse(self, courses):
        """
        :type courses: List[List[int]]
        :rtype: int
        """
        A = courses
        pq = []
        start = 0
        for t, end in sorted(A, key = lambda (t, end): end):
            start += t
            heapq.heappush(pq, -t)
            while start > end:
                start += heapq.heappop(pq)
        return len(pq)

相关文章

  • 8.27 - hard - 110

    630. Course Schedule III 现排序,再用heap,很多greedy的问题都可以这样来做。基本...

  • 8.27 - hard - 106

    588. Design In-Memory File System 一道设计题,还挺有意思的,可以再搞一遍

  • 8.27 - hard - 108

    600. Non-negative Integers without Consecutive Ones 这题的递推...

  • 8.27 - hard - 107

    591. Tag Validator 不太理解这道题的意义何在?? 直接抄了答案,并且不太想去理解答案,等到复习的...

  • 8.27 - hard - 109

    629. K Inverse Pairs Array递推公式如下f(n,k) = sum(f(n-1,i)), w...

  • 8.27棕色

  • 19/09/2017

    Work hard,play hard,study hard, love hard.一个小姐姐跟我这么说。她说后两...

  • 2018-09-06

    字号 110 110 110 110 110 110

  • 英文书法练习~learning

    learning is sometimes hard, But hard is not impossible.学习...

  • 你辛苦了。

    Thanks for your hard work. 重读:hard

网友评论

      本文标题:8.27 - hard - 110

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