mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-07 00:11:41 +08:00
移除零宽空格
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
"boundTopicId": 448044,
|
||||
"title": "Lexicographically Smallest String After Applying Operations",
|
||||
"titleSlug": "lexicographically-smallest-string-after-applying-operations",
|
||||
"content": "<p>You are given a string <code>s</code> of <strong>even length</strong> consisting of digits from <code>0</code> to <code>9</code>, and two integers <code>a</code> and <code>b</code>.</p>\n\n<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>\n\n<ul>\n\t<li>Add <code>a</code> to all odd indices of <code>s</code> <strong>(0-indexed)</strong>. Digits post <code>9</code> are cycled back to <code>0</code>. For example, if <code>s = "3456"</code> and <code>a = 5</code>, <code>s</code> becomes <code>"3951"</code>.</li>\n\t<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = "3456"</code> and <code>b = 1</code>, <code>s</code> becomes <code>"6345"</code>.</li>\n</ul>\n\n<p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain by applying the above operations any number of times on</em> <code>s</code>.</p>\n\n<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>. For example, <code>"0158"</code> is lexicographically smaller than <code>"0190"</code> because the first position they differ is at the third letter, and <code>'5'</code> comes before <code>'9'</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "5525", a = 9, b = 2\n<strong>Output:</strong> "2050"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "5525"\nRotate: "2555"\nAdd: "2454"\nAdd: "2353"\nRotate: "5323"\nAdd: "5222"\nAdd: "5121"\nRotate: "2151"\nAdd: "2050"\nThere is no way to obtain a string that is lexicographically smaller than "2050".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "74", a = 5, b = 1\n<strong>Output:</strong> "24"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "74"\nRotate: "47"\nAdd: "42"\nRotate: "24"\nThere is no way to obtain a string that is lexicographically smaller than "24".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "0011", a = 4, b = 2\n<strong>Output:</strong> "0011"\n<strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than "0011".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> is even.</li>\n\t<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> of <strong>even length</strong> consisting of digits from <code>0</code> to <code>9</code>, and two integers <code>a</code> and <code>b</code>.</p>\n\n<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>\n\n<ul>\n\t<li>Add <code>a</code> to all odd indices of <code>s</code> <strong>(0-indexed)</strong>. Digits post <code>9</code> are cycled back to <code>0</code>. For example, if <code>s = "3456"</code> and <code>a = 5</code>, <code>s</code> becomes <code>"3951"</code>.</li>\n\t<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = "3456"</code> and <code>b = 1</code>, <code>s</code> becomes <code>"6345"</code>.</li>\n</ul>\n\n<p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain by applying the above operations any number of times on</em> <code>s</code>.</p>\n\n<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>. For example, <code>"0158"</code> is lexicographically smaller than <code>"0190"</code> because the first position they differ is at the third letter, and <code>'5'</code> comes before <code>'9'</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "5525", a = 9, b = 2\n<strong>Output:</strong> "2050"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "5525"\nRotate: "2555"\nAdd: "2454"\nAdd: "2353"\nRotate: "5323"\nAdd: "5222"\nAdd: "5121"\nRotate: "2151"\nAdd: "2050"\nThere is no way to obtain a string that is lexicographically smaller than "2050".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "74", a = 5, b = 1\n<strong>Output:</strong> "24"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "74"\nRotate: "47"\nAdd: "42"\nRotate: "24"\nThere is no way to obtain a string that is lexicographically smaller than "24".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "0011", a = 4, b = 2\n<strong>Output:</strong> "0011"\n<strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than "0011".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> is even.</li>\n\t<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": "执行操作后字典序最小的字符串",
|
||||
"translatedContent": "<p>给你一个字符串 <code>s</code> 以及两个整数 <code>a</code> 和 <code>b</code> 。其中,字符串 <code>s</code> 的长度为偶数,且仅由数字 <code>0</code> 到 <code>9</code> 组成。</p>\n\n<p>你可以在 <code>s</code> 上按任意顺序多次执行下面两个操作之一:</p>\n\n<ul>\n\t<li>累加:将 <code>a</code> 加到 <code>s</code> 中所有下标为奇数的元素上(<strong>下标从 0 开始</strong>)。数字一旦超过 <code>9</code> 就会变成 <code>0</code>,如此循环往复。例如,<code>s = \"3456\"</code> 且 <code>a = 5</code>,则执行此操作后 <code>s</code> 变成 <code>\"3951\"</code>。</li>\n\t<li>轮转:将 <code>s</code> 向右轮转 <code>b</code> 位。例如,<code>s = \"3456\"</code> 且 <code>b = 1</code>,则执行此操作后 <code>s</code> 变成 <code>\"6345\"</code>。</li>\n</ul>\n\n<p>请你返回在 <code>s</code> 上执行上述操作任意次后可以得到的 <strong>字典序最小</strong> 的字符串。</p>\n\n<p>如果两个字符串长度相同,那么字符串 <code>a</code> 字典序比字符串 <code>b</code> 小可以这样定义:在 <code>a</code> 和 <code>b</code> 出现不同的第一个位置上,字符串 <code>a</code> 中的字符出现在字母表中的时间早于 <code>b</code> 中的对应字符。例如,<code>\"0158”</code> 字典序比 <code>\"0190\"</code> 小,因为不同的第一个位置是在第三个字符,显然 <code>'5'</code> 出现在 <code>'9'</code> 之前。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"5525\", a = 9, b = 2\n<strong>输出:</strong>\"2050\"\n<strong>解释:</strong>执行操作如下:\n初态:\"5525\"\n轮转:\"2555\"\n累加:\"2454\"\n累加:\"2353\"\n轮转:\"5323\"\n累加:\"5222\"\n累加:\"5121\"\n轮转:\"2151\"\n累加:\"2050\"\n无法获得字典序小于 \"2050\" 的字符串。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"74\", a = 5, b = 1\n<strong>输出:</strong>\"24\"\n<strong>解释:</strong>执行操作如下:\n初态:\"74\"\n轮转:\"47\"\n累加:\"42\"\n轮转:\"24\"\n无法获得字典序小于 \"24\" 的字符串。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"0011\", a = 4, b = 2\n<strong>输出:</strong>\"0011\"\n<strong>解释:</strong>无法获得字典序小于 \"0011\" 的字符串。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> 是偶数</li>\n\t<li><code>s</code> 仅由数字 <code>0</code> 到 <code>9</code> 组成</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"translatedContent": "<p>给你一个字符串 <code>s</code> 以及两个整数 <code>a</code> 和 <code>b</code> 。其中,字符串 <code>s</code> 的长度为偶数,且仅由数字 <code>0</code> 到 <code>9</code> 组成。</p>\n\n<p>你可以在 <code>s</code> 上按任意顺序多次执行下面两个操作之一:</p>\n\n<ul>\n\t<li>累加:将 <code>a</code> 加到 <code>s</code> 中所有下标为奇数的元素上(<strong>下标从 0 开始</strong>)。数字一旦超过 <code>9</code> 就会变成 <code>0</code>,如此循环往复。例如,<code>s = \"3456\"</code> 且 <code>a = 5</code>,则执行此操作后 <code>s</code> 变成 <code>\"3951\"</code>。</li>\n\t<li>轮转:将 <code>s</code> 向右轮转 <code>b</code> 位。例如,<code>s = \"3456\"</code> 且 <code>b = 1</code>,则执行此操作后 <code>s</code> 变成 <code>\"6345\"</code>。</li>\n</ul>\n\n<p>请你返回在 <code>s</code> 上执行上述操作任意次后可以得到的 <strong>字典序最小</strong> 的字符串。</p>\n\n<p>如果两个字符串长度相同,那么字符串 <code>a</code> 字典序比字符串 <code>b</code> 小可以这样定义:在 <code>a</code> 和 <code>b</code> 出现不同的第一个位置上,字符串 <code>a</code> 中的字符出现在字母表中的时间早于 <code>b</code> 中的对应字符。例如,<code>\"0158”</code> 字典序比 <code>\"0190\"</code> 小,因为不同的第一个位置是在第三个字符,显然 <code>'5'</code> 出现在 <code>'9'</code> 之前。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"5525\", a = 9, b = 2\n<strong>输出:</strong>\"2050\"\n<strong>解释:</strong>执行操作如下:\n初态:\"5525\"\n轮转:\"2555\"\n累加:\"2454\"\n累加:\"2353\"\n轮转:\"5323\"\n累加:\"5222\"\n累加:\"5121\"\n轮转:\"2151\"\n累加:\"2050\"\n无法获得字典序小于 \"2050\" 的字符串。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"74\", a = 5, b = 1\n<strong>输出:</strong>\"24\"\n<strong>解释:</strong>执行操作如下:\n初态:\"74\"\n轮转:\"47\"\n累加:\"42\"\n轮转:\"24\"\n无法获得字典序小于 \"24\" 的字符串。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"0011\", a = 4, b = 2\n<strong>输出:</strong>\"0011\"\n<strong>解释:</strong>无法获得字典序小于 \"0011\" 的字符串。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> 是偶数</li>\n\t<li><code>s</code> 仅由数字 <code>0</code> 到 <code>9</code> 组成</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 119,
|
||||
|
Reference in New Issue
Block a user