455. 分发饼干
让胃口最小的孩子先吃饱。
class Solution {
public int findContentChildren(int[] g, int[] s) {
// 贪心算法,给要求最少的孩子,分配可满足的最小的饼干。
Arrays.sort(g); // 要求最少
Arrays.sort(s); // 饼干最少
int start = 0;
int count = 0;
for(int i = 0;i<s.length && start<g.length;i++){
if(s[i] >= g[start]){
start++;
count++;
}
}
return count;
}
}