打折购买糖果的最小开销

LeetCode2144-打折购买糖果的最小开销(贪心算法)

#resource / algorithm #type / snippet #status / evergreen #source / leetcode #algo / greedy

[!info] related notes 算法面试题型 MOC 贪心算法

打折购买糖果的最小开销

题目

2144. 打折购买糖果的最小开销 - 力扣(LeetCode)

题解

贪心算法

var minimumCost = function(cost) {
    cost = cost.sort((a,b) => b - a);
    let index = 0;
    let res = 0;
    for (const c of cost) {
        index++
        if (index % 3 === 0) {
            continue
        }
        res += c;
    }
    return res;
};

参考

创建于 2025/1/1 更新于 2026/5/27