455. 分发饼干
两个快排,每次选择最少的。
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int i=0;
int j=0;
int count = 0;
while (i<g.length && j<s.length) {
if (g[i]<=s[j]) {
i++;
j++;
count++;
}
else {
j++;
}
}
return count;
}
}
时间复杂度: O(nlogn)
空间复杂度: O(1)