1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 05:26:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>一家商店正在打折销售糖果。每购买 <strong>两个</strong>&nbsp;糖果,商店会 <strong>免费</strong>&nbsp;送一个糖果。</p>\n\n<p>免费送的糖果唯一的限制是:它的价格需要小于等于购买的两个糖果价格的 <strong>较小值</strong>&nbsp;。</p>\n\n<ul>\n\t<li>比方说,总共有 <code>4</code>&nbsp;个糖果,价格分别为&nbsp;<code>1</code>&nbsp;<code>2</code>&nbsp;<code>3</code>&nbsp;和&nbsp;<code>4</code>&nbsp;,一位顾客买了价格为&nbsp;<code>2</code> 和&nbsp;<code>3</code>&nbsp;的糖果,那么他可以免费获得价格为 <code>1</code>&nbsp;的糖果,但不能获得价格为&nbsp;<code>4</code>&nbsp;的糖果。</li>\n</ul>\n\n<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>cost</code>&nbsp;,其中&nbsp;<code>cost[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;个糖果的价格,请你返回获得 <strong>所有</strong>&nbsp;糖果的 <strong>最小</strong>&nbsp;总开销。</p>\n\n<p>&nbsp;</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>&nbsp;方案。\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>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= cost.length &lt;= 100</code></li>\n\t<li><code>1 &lt;= cost[i] &lt;= 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?",