Package g0901_1000.s0942_di_string_match
Class Solution
java.lang.Object
g0901_1000.s0942_di_string_match.Solution
942 - DI String Match.<p>Easy</p>
<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>
<ul>
<li><code>s[i] == 'I'</code> if <code>perm[i] < perm[i + 1]</code>, and</li>
<li><code>s[i] == 'D'</code> if <code>perm[i] > perm[i + 1]</code>.</li>
</ul>
<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>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “IDID”</p>
<p><strong>Output:</strong> [0,4,1,3,2]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “III”</p>
<p><strong>Output:</strong> [0,1,2,3]</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “DDI”</p>
<p><strong>Output:</strong> [3,2,0,1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is either <code>'I'</code> or <code>'D'</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
diStringMatch
-