4 hours ago Leetcode每日一题 —— 2144. 打折购买糖果的最小开销🌐 链接: https://linux.do/t/topic/2281856🔍 关键词: #免费🏷️ 分组: LinuxDo论坛🕒 时间: 2026-06-01 09:03:37 LINUX DO Leetcode每日一题 —— 2144. 打折购买糖果的最小开销 思路 贪心,从贵到便宜,每三个一组,其中第三个是免费送的。剩余无法成组的直接加到结果里。 代码 class Solution { public int minimumCost(int[] cost) { Arrays.sort(cost); int ans = 0; int i = cost.length - 1; for (; i >= 2; i -= 3) { ans += cost[i] + cost[i…