Input: [1,2], [1,2,3]
Output: 2
Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2. You have 3 cookies and their sizes are big enough to gratify all of the children,
You need to output 2.
class Solution {
public int findContentChildren(int[] children, int[] cookies) {
Arrays.sort(children);
Arrays.sort(cookies);
int child=0,cookie=0;
while(child<children.length && cookie<cookies.length){
if(children[child]<=cookies[cookie]) child++;
cookie++;
}
return child;
}
}