刷题笔记
1528. Shuffle String
Given a string s and an integer array indices of the same length.
The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.
Return the shuffled string.
思路
- 首先这个问题将涉及三个数据类型,数组,字符和字符串。
- 对字符串进行重排,要首先创建一个字符数组来临时装重排的字符。
- 利用循环取出字符和对应的标签,利用标签来确定将字符放在字符数组的什么位置,利用string的charAt方法取出当前索引下的字符并放入前一句中所确定的位置中。
- 创建新字符串并将重排的字符数组传入,返回新字符串。
代码实现
class Solution