|
1 | | -## 484. Find Permutation |
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
2 | 7 |
|
| 8 | +## 484. Find Permutation (Medium) |
| 9 | + |
| 10 | +<p> |
| 11 | +By now, you are given a <b>secret signature</b> consisting of character 'D' and 'I'. 'D' represents a decreasing relationship between two numbers, 'I' represents an increasing relationship between two numbers. And our <b>secret signature</b> was constructed by a special integer array, which contains uniquely all the different number from 1 to n (n is the length of the secret signature plus 1). For example, the secret signature "DI" can be constructed by array [2,1,3] or [3,1,2], but won't be constructed by array [3,2,4] or [2,1,3,4], which are both illegal constructing special string that can't represent the "DI" <b>secret signature</b>. |
| 12 | +</p> |
| 13 | + |
| 14 | +<p> |
| 15 | +On the other hand, now your job is to find the lexicographically smallest permutation of [1, 2, ... n] could refer to the given <b>secret signature</b> in the input. |
| 16 | +</p> |
| 17 | + |
| 18 | +<p><b>Example 1:</b><br /> |
| 19 | +<pre><b>Input:</b> "I" |
| 20 | +<b>Output:</b> [1,2] |
| 21 | +<b>Explanation:</b> [1,2] is the only legal initial spectial string can construct secret signature "I", where the number 1 and 2 construct an increasing relationship. |
| 22 | +</pre> |
| 23 | +</p> |
| 24 | + |
| 25 | +<p><b>Example 2:</b><br /> |
| 26 | +<pre><b>Input:</b> "DI" |
| 27 | +<b>Output:</b> [2,1,3] |
| 28 | +<b>Explanation:</b> Both [2,1,3] and [3,1,2] can construct the secret signature "DI", </br>but since we want to find the one with the smallest lexicographical permutation, you need to output [2,1,3] |
| 29 | +</pre> |
| 30 | +</p> |
| 31 | + |
| 32 | +<p><b>Note:</b> |
| 33 | +<li>The input string will only contain the character 'D' and 'I'.</li> |
| 34 | +<li>The length of input string is a positive integer and will not exceed 10,000</li> |
| 35 | +</p> |
| 36 | + |
| 37 | +### Related Topics |
| 38 | + [[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)] |
0 commit comments