|  | 
|  | 1 | +<h2><a href="https://leetcode.com/problems/di-string-match">DI String Match</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>A permutation <code>perm</code> of <code>n + 1</code> integers of all the integers in the range <code>[0, n]</code> can be represented as a string <code>s</code> of length <code>n</code> where:</p> | 
|  | 2 | + | 
|  | 3 | +<ul> | 
|  | 4 | +	<li><code>s[i] == 'I'</code> if <code>perm[i] < perm[i + 1]</code>, and</li> | 
|  | 5 | +	<li><code>s[i] == 'D'</code> if <code>perm[i] > perm[i + 1]</code>.</li> | 
|  | 6 | +</ul> | 
|  | 7 | + | 
|  | 8 | +<p>Given a string <code>s</code>, reconstruct the permutation <code>perm</code> and return it. If there are multiple valid permutations perm, return <strong>any of them</strong>.</p> | 
|  | 9 | + | 
|  | 10 | +<p> </p> | 
|  | 11 | +<p><strong class="example">Example 1:</strong></p> | 
|  | 12 | +<pre><strong>Input:</strong> s = "IDID" | 
|  | 13 | +<strong>Output:</strong> [0,4,1,3,2] | 
|  | 14 | +</pre><p><strong class="example">Example 2:</strong></p> | 
|  | 15 | +<pre><strong>Input:</strong> s = "III" | 
|  | 16 | +<strong>Output:</strong> [0,1,2,3] | 
|  | 17 | +</pre><p><strong class="example">Example 3:</strong></p> | 
|  | 18 | +<pre><strong>Input:</strong> s = "DDI" | 
|  | 19 | +<strong>Output:</strong> [3,2,0,1] | 
|  | 20 | +</pre> | 
|  | 21 | +<p> </p> | 
|  | 22 | +<p><strong>Constraints:</strong></p> | 
|  | 23 | + | 
|  | 24 | +<ul> | 
|  | 25 | +	<li><code>1 <= s.length <= 10<sup>5</sup></code></li> | 
|  | 26 | +	<li><code>s[i]</code> is either <code>'I'</code> or <code>'D'</code>.</li> | 
|  | 27 | +</ul> | 
0 commit comments