mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
40 lines
1.3 KiB
HTML
40 lines
1.3 KiB
HTML
<p>由范围 <code>[0,n]</code> 内所有整数组成的 <code>n + 1</code> 个整数的排列序列可以表示为长度为 <code>n</code> 的字符串 <code>s</code> ,其中:</p>
|
||
|
||
<ul>
|
||
<li>如果 <code>perm[i] < perm[i + 1]</code> ,那么 <code>s[i] == 'I'</code> </li>
|
||
<li>如果 <code>perm[i] > perm[i + 1]</code> ,那么 <code>s[i] == 'D'</code> </li>
|
||
</ul>
|
||
|
||
<p>给定一个字符串 <code>s</code> ,重构排列 <code>perm</code> 并返回它。如果有多个有效排列perm,则返回其中 <strong>任何一个</strong> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>s = "IDID"
|
||
<strong>输出:</strong>[0,4,1,3,2]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>s = "III"
|
||
<strong>输出:</strong>[0,1,2,3]
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>s = "DDI"
|
||
<strong>输出:</strong>[3,2,0,1]</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||
<li><code><font color="#c7254e"><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size:12.6px"><span style="background-color:#f9f2f4">s</span></span></font></font></code> 只包含字符 <code>"I"</code> 或 <code>"D"</code></li>
|
||
</ul>
|