148. Leetcode 455. 分发饼干 (贪心算法-基础题目)

148. Leetcode 455. 分发饼干 (贪心算法-基础题目)_第1张图片

 

class Solution:
    def findContentChildren(self, g: List[int], s: List[int]) -> int:
        g.sort()
        s.sort()
        m = len(s)
        n = len(g)
        i = j = count = 0

        while i< n and j < m:
            while j < m and g[i] > s[j]:
                j += 1
            if j < m:
                count += 1

            i += 1
            j += 1

        return count

你可能感兴趣的:(2022刷题-目标400+,leetcode,贪心算法,算法)