package greedy; import java.util.Arrays; /** * 题目: 455. 分发饼干 (maxProfit) * 描述:给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 * 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 * 返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0 。 * 示例 1: 输入: g = [1,2,3], s = [1,1] 输出: 1 解释:你有三个孩子和两块小饼干,3 个孩子的胃口值分别是:1,2,3。 虽然你有两块小饼干,由于他们的尺寸都是 1,你只能让胃口值是 1 的孩子满足。 所以你应该输出 1。 * 链接:https://leetcode.cn/problems/assign-cookies/ */ public class FindContentChildren { public int findContentChildren(int[] g, int[] s) { int i=0,j=0,cnt=0; Arrays.sort(g); Arrays.sort(s); while (i