public class FindContentChildren { public static void main(String[] args) { int[] x = {1, 3, 3}; int[] y = {1, 2, 3, 4}; int contentChildren = findContentChildren(x, y); System.out.println("contentChildren = " + contentChildren); } public static int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int maxG = g.length - 1; int maxS = s.length - 1; int maxChildren = 0; while (maxG >= 0 && maxS >= 0) { if (g[maxG] <= s[maxS]) { maxG--; maxS--; maxChildren++; }else { maxG--; } } return maxChildren; } }
455.分发饼干
最新推荐文章于 2024-10-16 10:13:45 发布