2022-03-27 18:35:17 +08:00
|
|
|
<p>Given a string <code>s</code>, rearrange the characters of <code>s</code> so that any two adjacent characters are not the same.</p>
|
|
|
|
|
|
|
|
<p>Return <em>any possible rearrangement of</em> <code>s</code> <em>or return</em> <code>""</code> <em>if not possible</em>.</p>
|
|
|
|
|
|
|
|
<p> </p>
|
2023-12-09 18:42:21 +08:00
|
|
|
<p><strong class="example">Example 1:</strong></p>
|
2022-03-27 18:35:17 +08:00
|
|
|
<pre><strong>Input:</strong> s = "aab"
|
|
|
|
<strong>Output:</strong> "aba"
|
2023-12-09 18:42:21 +08:00
|
|
|
</pre><p><strong class="example">Example 2:</strong></p>
|
2022-03-27 18:35:17 +08:00
|
|
|
<pre><strong>Input:</strong> s = "aaab"
|
|
|
|
<strong>Output:</strong> ""
|
|
|
|
</pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>1 <= s.length <= 500</code></li>
|
|
|
|
<li><code>s</code> consists of lowercase English letters.</li>
|
|
|
|
</ul>
|