Skip to content

Commit faf048d

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 12.3 MB (83.94%)
1 parent 0b70753 commit faf048d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<p>You are given a string <code>s</code> and an integer array <code>indices</code> of the <strong>same length</strong>. The string <code>s</code> will be shuffled such that the character at the <code>i<sup>th</sup></code> position moves to <code>indices[i]</code> in the shuffled string.</p>
2+
3+
<p>Return <em>the shuffled string</em>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2020/07/09/q1.jpg" style="width: 321px; height: 243px;" />
8+
<pre>
9+
<strong>Input:</strong> s = &quot;codeleet&quot;, <code>indices</code> = [4,5,6,7,0,2,1,3]
10+
<strong>Output:</strong> &quot;leetcode&quot;
11+
<strong>Explanation:</strong> As shown, &quot;codeleet&quot; becomes &quot;leetcode&quot; after shuffling.
12+
</pre>
13+
14+
<p><strong class="example">Example 2:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> s = &quot;abc&quot;, <code>indices</code> = [0,1,2]
18+
<strong>Output:</strong> &quot;abc&quot;
19+
<strong>Explanation:</strong> After shuffling, each character remains in its position.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Constraints:</strong></p>
24+
25+
<ul>
26+
<li><code>s.length == indices.length == n</code></li>
27+
<li><code>1 &lt;= n &lt;= 100</code></li>
28+
<li><code>s</code> consists of only lowercase English letters.</li>
29+
<li><code>0 &lt;= indices[i] &lt; n</code></li>
30+
<li>All values of <code>indices</code> are <strong>unique</strong>.</li>
31+
</ul>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def restoreString(self, s, indices):
3+
"""
4+
:type s: str
5+
:type indices: List[int]
6+
:rtype: str
7+
"""
8+
ans = ["X"] * len(indices)
9+
for i, idx in enumerate(indices):
10+
ans[idx] = s[i]
11+
return "".join(ans)
12+
13+

0 commit comments

Comments
 (0)