-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode-string.html
39 lines (28 loc) · 1.49 KB
/
decode-string.html
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
<p>Given an encoded string, return its decoded string.</p>
<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. Note that <code>k</code> is guaranteed to be a positive integer.</p>
<p>You may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc.</p>
<p>Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, <code>k</code>. For example, there will not be input like <code>3a</code> or <code>2[4]</code>.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "3[a]2[bc]"
<strong>Output:</strong> "aaabcbc"
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = "3[a2[c]]"
<strong>Output:</strong> "accaccacc"
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = "2[abc]3[cd]ef"
<strong>Output:</strong> "abcabccdcdcdef"
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 30</code></li>
<li><code>s</code> consists of lowercase English letters, digits, and square brackets <code>'[]'</code>.</li>
<li><code>s</code> is guaranteed to be <strong>a valid</strong> input.</li>
<li>All the integers in <code>s</code> are in the range <code>[1, 300]</code>.</li>
</ul>