如题
思路很清晰,每一块饼干匹配尽可能大的孩子即可
public static int findContentChildren(int[] g, int[] s) {
int count =0;
Arrays.sort(g);
Arrays.sort(s);
int m = s.length-1;//倒序从大到小检索
int n = g.length-1;
while(m>=0&&n>=0) {
if(s[m]>=g[n]) {//符合规则匹配下一对
m--;
n--;
count++;
}else {//否则匹配更小胃口的孩子
n--;
}
}
return count;
}