1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-07 08:21:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 16:56:27 +08:00
parent e730aa6794
commit ad15da05aa
2517 changed files with 7358 additions and 7332 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>几张卡牌<strong> 排成一行</strong>,每张卡牌都有一个对应的点数。点数由整数数组 <code>cardPoints</code> 给出。</p>\n\n<p>每次行动,你可以从行的开头或者末尾拿一张卡牌,最终你必须正好拿 <code>k</code> 张卡牌。</p>\n\n<p>你的点数就是你拿到手中的所有卡牌的点数之和。</p>\n\n<p>给你一个整数数组 <code>cardPoints</code> 和整数 <code>k</code>,请你返回可以获得的最大点数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>cardPoints = [1,2,3,4,5,6,1], k = 3\n<strong>输出:</strong>12\n<strong>解释:</strong>第一次行动,不管拿哪张牌,你的点数总是 1 。但是,先拿最右边的卡牌将会最大化你的可获得点数。最优策略是拿右边的三张牌,最终点数为 1 + 6 + 5 = 12 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>cardPoints = [2,2,2], k = 2\n<strong>输出:</strong>4\n<strong>解释:</strong>无论你拿起哪两张卡牌,可获得的点数总是 4 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><strong>输入:</strong>cardPoints = [9,7,7,9,7,7,9], k = 7\n<strong>输出:</strong>55\n<strong>解释:</strong>你必须拿起所有卡牌,可以获得的点数为所有卡牌的点数之和。\n</pre>\n\n<p><strong>示例 4</strong></p>\n\n<pre><strong>输入:</strong>cardPoints = [1,1000,1], k = 1\n<strong>输出:</strong>1\n<strong>解释:</strong>你无法拿到中间那张卡牌,所以可以获得的最大点数为 1 。 \n</pre>\n\n<p><strong>示例 5</strong></p>\n\n<pre><strong>输入:</strong>cardPoints = [1,79,80,1,1,1,200,1], k = 3\n<strong>输出:</strong>202\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= cardPoints.length &lt;= 10^5</code></li>\n\t<li><code>1 &lt;= cardPoints[i] &lt;= 10^4</code></li>\n\t<li><code>1 &lt;= k &lt;= cardPoints.length</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 215,
"likes": 216,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"38.6K\", \"totalSubmission\": \"69.6K\", \"totalAcceptedRaw\": 38600, \"totalSubmissionRaw\": 69554, \"acRate\": \"55.5%\"}",
"stats": "{\"totalAccepted\": \"38.7K\", \"totalSubmission\": \"69.7K\", \"totalAcceptedRaw\": 38706, \"totalSubmissionRaw\": 69715, \"acRate\": \"55.5%\"}",
"hints": [
"Let the sum of all points be total_pts. You need to remove a sub-array from cardPoints with length n - k.",
"Keep a window of size n - k over the array. The answer is max(answer, total_pts - sumOfCurrentWindow)"