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;
    }
}
原文地址:https://www.cnblogs.com/liuyongyu/p/14187538.html