mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 07:21:40 +08:00
update
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"boundTopicId": 1819,
|
||||
"title": "Baseball Game",
|
||||
"titleSlug": "baseball-game",
|
||||
"content": "<p>You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.</p>\n\n<p>At the beginning of the game, you start with an empty record. You are given a list of strings <code>ops</code>, where <code>ops[i]</code> is the <code>i<sup>th</sup></code> operation you must apply to the record and is one of the following:</p>\n\n<ol>\n\t<li>An integer <code>x</code> - Record a new score of <code>x</code>.</li>\n\t<li><code>"+"</code> - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.</li>\n\t<li><code>"D"</code> - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.</li>\n\t<li><code>"C"</code> - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.</li>\n</ol>\n\n<p>Return <em>the sum of all the scores on the record</em>.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["5","2","C","D","+"]\n<strong>Output:</strong> 30\n<strong>Explanation:</strong>\n"5" - Add 5 to the record, record is now [5].\n"2" - Add 2 to the record, record is now [5, 2].\n"C" - Invalidate and remove the previous score, record is now [5].\n"D" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n"+" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\nThe total sum is 5 + 10 + 15 = 30.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["5","-2","4","C","D","9","+","+"]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\n"5" - Add 5 to the record, record is now [5].\n"-2" - Add -2 to the record, record is now [5, -2].\n"4" - Add 4 to the record, record is now [5, -2, 4].\n"C" - Invalidate and remove the previous score, record is now [5, -2].\n"D" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n"9" - Add 9 to the record, record is now [5, -2, -4, 9].\n"+" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n"+" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\nThe total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["1"]\n<strong>Output:</strong> 1\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= ops.length <= 1000</code></li>\n\t<li><code>ops[i]</code> is <code>"C"</code>, <code>"D"</code>, <code>"+"</code>, or a string representing an integer in the range <code>[-3 * 10<sup>4</sup>, 3 * 10<sup>4</sup>]</code>.</li>\n\t<li>For operation <code>"+"</code>, there will always be at least two previous scores on the record.</li>\n\t<li>For operations <code>"C"</code> and <code>"D"</code>, there will always be at least one previous score on the record.</li>\n</ul>\n",
|
||||
"content": "<p>You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds' scores.</p>\n\n<p>At the beginning of the game, you start with an empty record. You are given a list of strings <code>ops</code>, where <code>ops[i]</code> is the <code>i<sup>th</sup></code> operation you must apply to the record and is one of the following:</p>\n\n<ol>\n\t<li>An integer <code>x</code> - Record a new score of <code>x</code>.</li>\n\t<li><code>"+"</code> - Record a new score that is the sum of the previous two scores. It is guaranteed there will always be two previous scores.</li>\n\t<li><code>"D"</code> - Record a new score that is double the previous score. It is guaranteed there will always be a previous score.</li>\n\t<li><code>"C"</code> - Invalidate the previous score, removing it from the record. It is guaranteed there will always be a previous score.</li>\n</ol>\n\n<p>Return <em>the sum of all the scores on the record</em>. The test cases are generated so that the answer fits in a 32-bit integer.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["5","2","C","D","+"]\n<strong>Output:</strong> 30\n<strong>Explanation:</strong>\n"5" - Add 5 to the record, record is now [5].\n"2" - Add 2 to the record, record is now [5, 2].\n"C" - Invalidate and remove the previous score, record is now [5].\n"D" - Add 2 * 5 = 10 to the record, record is now [5, 10].\n"+" - Add 5 + 10 = 15 to the record, record is now [5, 10, 15].\nThe total sum is 5 + 10 + 15 = 30.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["5","-2","4","C","D","9","+","+"]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\n"5" - Add 5 to the record, record is now [5].\n"-2" - Add -2 to the record, record is now [5, -2].\n"4" - Add 4 to the record, record is now [5, -2, 4].\n"C" - Invalidate and remove the previous score, record is now [5, -2].\n"D" - Add 2 * -2 = -4 to the record, record is now [5, -2, -4].\n"9" - Add 9 to the record, record is now [5, -2, -4, 9].\n"+" - Add -4 + 9 = 5 to the record, record is now [5, -2, -4, 9, 5].\n"+" - Add 9 + 5 = 14 to the record, record is now [5, -2, -4, 9, 5, 14].\nThe total sum is 5 + -2 + -4 + 9 + 5 + 14 = 27.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> ops = ["1"]\n<strong>Output:</strong> 1\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= ops.length <= 1000</code></li>\n\t<li><code>ops[i]</code> is <code>"C"</code>, <code>"D"</code>, <code>"+"</code>, or a string representing an integer in the range <code>[-3 * 10<sup>4</sup>, 3 * 10<sup>4</sup>]</code>.</li>\n\t<li>For operation <code>"+"</code>, there will always be at least two previous scores on the record.</li>\n\t<li>For operations <code>"C"</code> and <code>"D"</code>, there will always be at least one previous score on the record.</li>\n</ul>\n",
|
||||
"translatedTitle": "棒球比赛",
|
||||
"translatedContent": "<p>你现在是一场采用特殊赛制棒球比赛的记录员。这场比赛由若干回合组成,过去几回合的得分可能会影响以后几回合的得分。</p>\n\n<p>比赛开始时,记录是空白的。你会得到一个记录操作的字符串列表 <code>ops</code>,其中 <code>ops[i]</code> 是你需要记录的第 <code>i</code> 项操作,<code>ops</code> 遵循下述规则:</p>\n\n<ol>\n\t<li>整数 <code>x</code> - 表示本回合新获得分数 <code>x</code></li>\n\t<li><code>\"+\"</code> - 表示本回合新获得的得分是前两次得分的总和。题目数据保证记录此操作时前面总是存在两个有效的分数。</li>\n\t<li><code>\"D\"</code> - 表示本回合新获得的得分是前一次得分的两倍。题目数据保证记录此操作时前面总是存在一个有效的分数。</li>\n\t<li><code>\"C\"</code> - 表示前一次得分无效,将其从记录中移除。题目数据保证记录此操作时前面总是存在一个有效的分数。</li>\n</ol>\n\n<p>请你返回记录中所有得分的总和。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>ops = [\"5\",\"2\",\"C\",\"D\",\"+\"]\n<strong>输出:</strong>30\n<strong>解释:</strong>\n\"5\" - 记录加 5 ,记录现在是 [5]\n\"2\" - 记录加 2 ,记录现在是 [5, 2]\n\"C\" - 使前一次得分的记录无效并将其移除,记录现在是 [5].\n\"D\" - 记录加 2 * 5 = 10 ,记录现在是 [5, 10].\n\"+\" - 记录加 5 + 10 = 15 ,记录现在是 [5, 10, 15].\n所有得分的总和 5 + 10 + 15 = 30\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]\n<strong>输出:</strong>27\n<strong>解释:</strong>\n\"5\" - 记录加 5 ,记录现在是 [5]\n\"-2\" - 记录加 -2 ,记录现在是 [5, -2]\n\"4\" - 记录加 4 ,记录现在是 [5, -2, 4]\n\"C\" - 使前一次得分的记录无效并将其移除,记录现在是 [5, -2]\n\"D\" - 记录加 2 * -2 = -4 ,记录现在是 [5, -2, -4]\n\"9\" - 记录加 9 ,记录现在是 [5, -2, -4, 9]\n\"+\" - 记录加 -4 + 9 = 5 ,记录现在是 [5, -2, -4, 9, 5]\n\"+\" - 记录加 9 + 5 = 14 ,记录现在是 [5, -2, -4, 9, 5, 14]\n所有得分的总和 5 + -2 + -4 + 9 + 5 + 14 = 27\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>ops = [\"1\"]\n<strong>输出:</strong>1\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= ops.length <= 1000</code></li>\n\t<li><code>ops[i]</code> 为 <code>\"C\"</code>、<code>\"D\"</code>、<code>\"+\"</code>,或者一个表示整数的字符串。整数范围是 <code>[-3 * 10<sup>4</sup>, 3 * 10<sup>4</sup>]</code></li>\n\t<li>对于 <code>\"+\"</code> 操作,题目数据保证记录此操作时前面总是存在两个有效的分数</li>\n\t<li>对于 <code>\"C\"</code> 和 <code>\"D\"</code> 操作,题目数据保证记录此操作时前面总是存在一个有效的分数</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"78.6K\", \"totalSubmission\": \"108.6K\", \"totalAcceptedRaw\": 78558, \"totalSubmissionRaw\": 108618, \"acRate\": \"72.3%\"}",
|
||||
"stats": "{\"totalAccepted\": \"80.1K\", \"totalSubmission\": \"110.8K\", \"totalAcceptedRaw\": 80053, \"totalSubmissionRaw\": 110790, \"acRate\": \"72.3%\"}",
|
||||
"hints": [],
|
||||
"solution": {
|
||||
"id": "97",
|
||||
|
Reference in New Issue
Block a user