455. Assign Cookies[LeetCode]分糖果

2018-02-15  本文已影响0人  Jonddy

钞票支付问题:
有1元、5元、10元、20元、100元、200元面额的钞票无穷张,现使用这些钞票支付628元,需要多少张?
最佳的支付方式:3张200元,1张20元,1张5元,3张1元。
直觉告诉我们:尽可能多的使用面值较大的钞票。

LeetCode455:
题意和实例
思路:
思路
贪心规律:
贪心规律
伪代码
Python代码:
class Solution(object):
    def findContentChildren(self, g, s):
        """
        :type g: List[int]
        :type s: List[int]
        :rtype: int
        """
        child = 0
        cookie = 0
        
        g.sort()
        s.sort()
        while child < len(g) and cookie < len(s):
            if g[child] <= s[cookie]:
                child += 1
            cookie += 1
        return child
上一篇 下一篇

猜你喜欢

热点阅读