mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 16:31:42 +08:00
移除零宽空格
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"boundTopicId": 1422361,
|
||||
"title": "Calculate Digit Sum of a String",
|
||||
"titleSlug": "calculate-digit-sum-of-a-string",
|
||||
"content": "<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>\n\n<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the following:</p>\n\n<ol>\n\t<li><strong>Divide</strong> <code>s</code> into <strong>consecutive groups</strong> of size <code>k</code> such that the first <code>k</code> characters are in the first group, the next <code>k</code> characters are in the second group, and so on. <strong>Note</strong> that the size of the last group can be smaller than <code>k</code>.</li>\n\t<li><strong>Replace</strong> each group of <code>s</code> with a string representing the sum of all its digits. For example, <code>"346"</code> is replaced with <code>"13"</code> because <code>3 + 4 + 6 = 13</code>.</li>\n\t<li><strong>Merge</strong> consecutive groups together to form a new string. If the length of the string is greater than <code>k</code>, repeat from step <code>1</code>.</li>\n</ol>\n\n<p>Return <code>s</code> <em>after all rounds have been completed</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "11111222223", k = 3\n<strong>Output:</strong> "135"\n<strong>Explanation:</strong> \n- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".\n Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. \n So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.\n- For the second round, we divide s into "346" and "5".\n Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. \n So, s becomes "13" + "5" = "135" after second round. \nNow, s.length <= k, so we return "135" as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "00000000", k = 3\n<strong>Output:</strong> "000"\n<strong>Explanation:</strong> \nWe divide s into "000", "000", and "00".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. \ns becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>2 <= k <= 100</code></li>\n\t<li><code>s</code> consists of digits only.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>\n\n<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the following:</p>\n\n<ol>\n\t<li><strong>Divide</strong> <code>s</code> into <strong>consecutive groups</strong> of size <code>k</code> such that the first <code>k</code> characters are in the first group, the next <code>k</code> characters are in the second group, and so on. <strong>Note</strong> that the size of the last group can be smaller than <code>k</code>.</li>\n\t<li><strong>Replace</strong> each group of <code>s</code> with a string representing the sum of all its digits. For example, <code>"346"</code> is replaced with <code>"13"</code> because <code>3 + 4 + 6 = 13</code>.</li>\n\t<li><strong>Merge</strong> consecutive groups together to form a new string. If the length of the string is greater than <code>k</code>, repeat from step <code>1</code>.</li>\n</ol>\n\n<p>Return <code>s</code> <em>after all rounds have been completed</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "11111222223", k = 3\n<strong>Output:</strong> "135"\n<strong>Explanation:</strong> \n- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".\n Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. \n So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.\n- For the second round, we divide s into "346" and "5".\n Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. \n So, s becomes "13" + "5" = "135" after second round. \nNow, s.length <= k, so we return "135" as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "00000000", k = 3\n<strong>Output:</strong> "000"\n<strong>Explanation:</strong> \nWe divide s into "000", "000", and "00".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. \ns becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>2 <= k <= 100</code></li>\n\t<li><code>s</code> consists of digits only.</li>\n</ul>\n",
|
||||
"translatedTitle": "计算字符串的数字和",
|
||||
"translatedContent": "<p>给你一个由若干数字(<code>0</code> - <code>9</code>)组成的字符串 <code>s</code> ,和一个整数。</p>\n\n<p>如果 <code>s</code> 的长度大于 <code>k</code> ,则可以执行一轮操作。在一轮操作中,需要完成以下工作:</p>\n\n<ol>\n\t<li>将 <code>s</code> <strong>拆分 </strong>成长度为 <code>k</code> 的若干 <strong>连续数字组</strong> ,使得前 <code>k</code> 个字符都分在第一组,接下来的 <code>k</code> 个字符都分在第二组,依此类推。<strong>注意</strong>,最后一个数字组的长度可以小于 <code>k</code> 。</li>\n\t<li>用表示每个数字组中所有数字之和的字符串来 <strong>替换</strong> 对应的数字组。例如,<code>\"346\"</code> 会替换为 <code>\"13\"</code> ,因为 <code>3 + 4 + 6 = 13</code> 。</li>\n\t<li><strong>合并</strong> 所有组以形成一个新字符串。如果新字符串的长度大于 <code>k</code> 则重复第一步。</li>\n</ol>\n\n<p>返回在完成所有轮操作后的 <code>s</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>s = \"11111222223\", k = 3\n<strong>输出:</strong>\"135\"\n<strong>解释:</strong>\n- 第一轮,将 s 分成:\"111\"、\"112\"、\"222\" 和 \"23\" 。\n 接着,计算每一组的数字和:1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。 \n 这样,s 在第一轮之后变成 \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" 。\n- 第二轮,将 s 分成:\"346\" 和 \"5\" 。\n 接着,计算每一组的数字和:3 + 4 + 6 = 13 、5 = 5 。\n 这样,s 在第二轮之后变成 \"13\" + \"5\" = \"135\" 。 \n现在,s.length <= k ,所以返回 \"135\" 作为答案。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>s = \"00000000\", k = 3\n<strong>输出:</strong>\"000\"\n<strong>解释:</strong>\n将 \"000\", \"000\", and \"00\".\n接着,计算每一组的数字和:0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。 \ns 变为 \"0\" + \"0\" + \"0\" = \"000\" ,其长度等于 k ,所以返回 \"000\" 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>2 <= k <= 100</code></li>\n\t<li><code>s</code> 仅由数字(<code>0</code> - <code>9</code>)组成。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
|
Reference in New Issue
Block a user