-
Notifications
You must be signed in to change notification settings - Fork 161
/
di-string-match.md
43 lines (31 loc) · 1.34 KB
/
di-string-match.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<p>Given a string <code>S</code> that <strong>only</strong> contains "I" (increase) or "D" (decrease), let <code>N = S.length</code>.</p>
<p>Return <strong>any</strong> permutation <code>A</code> of <code>[0, 1, ..., N]</code> such that for all <code>i = 0, ..., N-1</code>:</p>
<ul>
<li>If <code>S[i] == "I"</code>, then <code>A[i] < A[i+1]</code></li>
<li>If <code>S[i] == "D"</code>, then <code>A[i] > A[i+1]</code></li>
</ul>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-1-1">"IDID"</span>
<strong>Output: </strong><span id="example-output-1">[0,4,1,3,2]</span>
</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-2-1">"III"</span>
<strong>Output: </strong><span id="example-output-2">[0,1,2,3]</span>
</pre>
<div>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input: </strong><span id="example-input-3-1">"DDI"</span>
<strong>Output: </strong><span id="example-output-3">[3,2,0,1]</span></pre>
</div>
</div>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 <= S.length <= 10000</code></li>
<li><code>S</code> only contains characters <code>"I"</code> or <code>"D"</code>.</li>
</ol>