Class Solution

java.lang.Object
g1501_1600.s1528_shuffle_string.Solution

public class Solution extends Object
1528 - Shuffle String.<p>Easy</p> <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> <p>Return <em>the shuffled string</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/07/09/q1.jpg" alt="" /></p> <p><strong>Input:</strong> s = &ldquo;codeleet&rdquo;, <code>indices</code> = [4,5,6,7,0,2,1,3]</p> <p><strong>Output:</strong> &ldquo;leetcode&rdquo;</p> <p><strong>Explanation:</strong> As shown, &ldquo;codeleet&rdquo; becomes &ldquo;leetcode&rdquo; after shuffling.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;abc&rdquo;, <code>indices</code> = [0,1,2]</p> <p><strong>Output:</strong> &ldquo;abc&rdquo;</p> <p><strong>Explanation:</strong> After shuffling, each character remains in its position.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>s.length == indices.length == n</code></li> <li><code>1 <= n <= 100</code></li> <li><code>s</code> consists of only lowercase English letters.</li> <li><code>0 <= indices[i] < n</code></li> <li>All values of <code>indices</code> are <strong>unique</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • restoreString

      public String restoreString(String s, int[] indices)