1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/重新格式化字符串 [reformat-the-string].html
2022-03-29 12:43:11 +08:00

50 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个混合了数字和字母的字符串 <code>s</code>,其中的字母均为小写英文字母。</p>
<p>请你将该字符串重新格式化,使得任意两个相邻字符的类型都不同。也就是说,字母后面应该跟着数字,而数字后面应该跟着字母。</p>
<p>请你返回 <strong>重新格式化后</strong> 的字符串;如果无法按要求重新格式化,则返回一个 <strong>空字符串</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = &quot;a0b1c2&quot;
<strong>输出:</strong>&quot;0a1b2c&quot;
<strong>解释:</strong>&quot;0a1b2c&quot; 中任意两个相邻字符的类型都不同。 &quot;a0b1c2&quot;, &quot;0a1b2c&quot;, &quot;0c2a1b&quot; 也是满足题目要求的答案。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = &quot;leetcode&quot;
<strong>输出:</strong>&quot;&quot;
<strong>解释:</strong>&quot;leetcode&quot; 中只有字母,所以无法满足重新格式化的条件。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>s = &quot;1229857369&quot;
<strong>输出:</strong>&quot;&quot;
<strong>解释:</strong>&quot;1229857369&quot; 中只有数字,所以无法满足重新格式化的条件。
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>s = &quot;covid2019&quot;
<strong>输出:</strong>&quot;c2o0v1i9d&quot;
</pre>
<p><strong>示例 5</strong></p>
<pre><strong>输入:</strong>s = &quot;ab123&quot;
<strong>输出:</strong>&quot;1a2b3&quot;
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 500</code></li>
<li><code>s</code> 仅由小写英文字母和/或数字组成。</li>
</ul>