1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 23:41:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2023-12-09 19:57:46 +08:00
parent 9bc4722a45
commit 3770b44d1e
4792 changed files with 10889 additions and 10886 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>请你来实现一个&nbsp;<code>myAtoi(string s)</code>&nbsp;函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 <code>atoi</code> 函数)。</p>\n\n<p>函数&nbsp;<code>myAtoi(string s)</code> 的算法如下:</p>\n\n<ol>\n\t<li>读入字符串并丢弃无用的前导空格</li>\n\t<li>检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有)。 确定最终结果是负数还是正数。 如果两者都不存在,则假定结果为正。</li>\n\t<li>读入下一个字符,直到到达下一个非数字字符或到达输入的结尾。字符串的其余部分将被忽略。</li>\n\t<li>将前面步骤读入的这些数字转换为整数(即,\"123\" -&gt; 123 \"0032\" -&gt; 32。如果没有读入数字则整数为 <code>0</code> 。必要时更改符号(从步骤 2 开始)。</li>\n\t<li>如果整数数超过 32 位有符号整数范围 <code>[2<sup>31</sup>,&nbsp; 2<sup>31&nbsp;</sup> 1]</code> ,需要截断这个整数,使其保持在这个范围内。具体来说,小于 <code>2<sup>31</sup></code> 的整数应该被固定为 <code>2<sup>31</sup></code> ,大于 <code>2<sup>31&nbsp;</sup> 1</code> 的整数应该被固定为 <code>2<sup>31&nbsp;</sup> 1</code> 。</li>\n\t<li>返回整数作为最终结果。</li>\n</ol>\n\n<p><strong>注意:</strong></p>\n\n<ul>\n\t<li>本题中的空白字符只包括空格字符 <code>' '</code> 。</li>\n\t<li>除前导空格或数字后的其余字符串外,<strong>请勿忽略</strong> 任何其他字符。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例&nbsp;1</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"42\"\n<strong>输出:</strong>42\n<strong>解释:</strong>加粗的字符串为已经读入的字符,插入符号是当前读取的字符。\n第 1 步:\"42\"(当前没有读入字符,因为没有前导空格)\n ^\n第 2 步:\"42\"(当前没有读入字符,因为这里不存在 '-' 或者 '+'\n ^\n第 3 步:\"<u>42</u>\"(读入 \"42\"\n ^\n解析得到整数 42 。\n由于 \"42\" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 42 。</pre>\n\n<p><strong>示例&nbsp;2</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \" -42\"\n<strong>输出:</strong>-42\n<strong>解释:</strong>\n第 1 步:\"<u><strong> </strong></u>-42\"(读入前导空格,但忽视掉)\n ^\n第 2 步:\" <u><strong>-</strong></u>42\"(读入 '-' 字符,所以结果应该是负数)\n ^\n第 3 步:\" <u><strong>-42</strong></u>\"(读入 \"42\"\n ^\n解析得到整数 -42 。\n由于 \"-42\" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 -42 。\n</pre>\n\n<p><strong>示例&nbsp;3</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"4193 with words\"\n<strong>输出:</strong>4193\n<strong>解释:</strong>\n第 1 步:\"4193 with words\"(当前没有读入字符,因为没有前导空格)\n ^\n第 2 步:\"4193 with words\"(当前没有读入字符,因为这里不存在 '-' 或者 '+'\n ^\n第 3 步:\"<u>4193</u> with words\"(读入 \"4193\";由于下一个字符不是一个数字,所以读入停止)\n ^\n解析得到整数 4193 。\n由于 \"4193\" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 4193 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 &lt;= s.length &lt;= 200</code></li>\n\t<li><code>s</code> 由英文字母(大写和小写)、数字(<code>0-9</code>)、<code>' '</code>、<code>'+'</code>、<code>'-'</code> 和 <code>'.'</code> 组成</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 1772,
"likes": 1773,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Reverse Integer\", \"titleSlug\": \"reverse-integer\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u6574\\u6570\\u53cd\\u8f6c\", \"isPaidOnly\": false}, {\"title\": \"Valid Number\", \"titleSlug\": \"valid-number\", \"difficulty\": \"Hard\", \"translatedTitle\": \"\\u6709\\u6548\\u6570\\u5b57\", \"isPaidOnly\": false}]",
@@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"614.6K\", \"totalSubmission\": \"2.9M\", \"totalAcceptedRaw\": 614593, \"totalSubmissionRaw\": 2900691, \"acRate\": \"21.2%\"}",
"stats": "{\"totalAccepted\": \"614.7K\", \"totalSubmission\": \"2.9M\", \"totalAcceptedRaw\": 614672, \"totalSubmissionRaw\": 2900917, \"acRate\": \"21.2%\"}",
"hints": [],
"solution": null,
"status": null,