python leetcode 455. Assign Cookies

按照题目意思编写即可  贪心策略

饼干按照能分配的情况下先给体重轻的孩子分配

class Solution:
    def findContentChildren(self, g, s):
        """
        :type g: List[int]
        :type s: List[int]
        :rtype: int
        """
        g.sort()
        s.sort()
        i=j=0
        count=0
        while i<len(g) and j<len(s):
            if g[i]<=s[j]:
                count+=1
                i+=1
                j+=1
            else:
                j+=1 
        return count

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84747429