mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 05:26:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>一家商店正在打折销售糖果。每购买 <strong>两个</strong> 糖果,商店会 <strong>免费</strong> 送一个糖果。</p>\n\n<p>免费送的糖果唯一的限制是:它的价格需要小于等于购买的两个糖果价格的 <strong>较小值</strong> 。</p>\n\n<ul>\n\t<li>比方说,总共有 <code>4</code> 个糖果,价格分别为 <code>1</code> ,<code>2</code> ,<code>3</code> 和 <code>4</code> ,一位顾客买了价格为 <code>2</code> 和 <code>3</code> 的糖果,那么他可以免费获得价格为 <code>1</code> 的糖果,但不能获得价格为 <code>4</code> 的糖果。</li>\n</ul>\n\n<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>cost</code> ,其中 <code>cost[i]</code> 表示第 <code>i</code> 个糖果的价格,请你返回获得 <strong>所有</strong> 糖果的 <strong>最小</strong> 总开销。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><b>输入:</b>cost = [1,2,3]\n<b>输出:</b>5\n<b>解释:</b>我们购买价格为 2 和 3 的糖果,然后免费获得价格为 1 的糖果。\n总开销为 2 + 3 = 5 。这是开销最小的 <strong>唯一</strong> 方案。\n注意,我们不能购买价格为 1 和 3 的糖果,并免费获得价格为 2 的糖果。\n这是因为免费糖果的价格必须小于等于购买的 2 个糖果价格的较小值。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><b>输入:</b>cost = [6,5,7,9,2,2]\n<b>输出:</b>23\n<b>解释:</b>最小总开销购买糖果方案为:\n- 购买价格为 9 和 7 的糖果\n- 免费获得价格为 6 的糖果\n- 购买价格为 5 和 2 的糖果\n- 免费获得价格为 2 的最后一个糖果\n因此,最小总开销为 9 + 7 + 5 + 2 = 23 。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><b>输入:</b>cost = [5,5]\n<b>输出:</b>10\n<b>解释:</b>由于只有 2 个糖果,我们需要将它们都购买,而且没有免费糖果。\n所以总最小开销为 5 + 5 = 10 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= cost.length <= 100</code></li>\n\t<li><code>1 <= cost[i] <= 100</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 6,
|
||||
"likes": 7,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"5.5K\", \"totalSubmission\": \"7.9K\", \"totalAcceptedRaw\": 5458, \"totalSubmissionRaw\": 7903, \"acRate\": \"69.1%\"}",
|
||||
"stats": "{\"totalAccepted\": \"5.9K\", \"totalSubmission\": \"8.6K\", \"totalAcceptedRaw\": 5899, \"totalSubmissionRaw\": 8587, \"acRate\": \"68.7%\"}",
|
||||
"hints": [
|
||||
"If we consider costs from high to low, what is the maximum cost of a single candy that we can get for free?",
|
||||
"How can we generalize this approach to maximize the costs of the candies we get for free?",
|
||||
|
Reference in New Issue
Block a user