Loading

Leetcode455.分发饼干

题目链接:455.分发饼干

思路:排序。

代码:

class Solution {
    public int findContentChildren(int[] g, int[] s) {
        int cnt = 0;
        Arrays.sort(g);
        Arrays.sort(s);
        for(int i=0, j=0; i<g.length && j<s.length;i++,j++){
            while(j<s.length && g[i]>s[j]) j++;
            if(j<s.length){
                cnt++;
            }
        }
        return cnt;
    }
}

 

posted @ 2020-12-25 10:01  yoyuLiu  阅读(72)  评论(0编辑  收藏  举报