分发饼干-贪心

阅读 135

2022-02-13

  • 题目
  • 示例
  • 算法
  • 代码
class Solution {
    public int findContentChildren(int[] g, int[] s) {
        int i = 0;
        int j = 0;
        int res = 0;
        Arrays.sort(g);
        Arrays.sort(s);
        while (i < g.length && j < s.length) {
            if (s[j] >= g[i]) {
                res++;
                i++;
            } 
            j++;
        }
        return res;
    }
}

相关推荐

精彩评论(0)

0 0 举报