Leetcode 1528. Shuffle String

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Shuffle String

2. Solution

解析:Version 1,根据要求,按顺序将字母填到对应位置即可。

  • Version 1
1
2
3
4
5
6
class Solution:
def restoreString(self, s: str, indices: List[int]) -> str:
res = ['0'] * len(s)
for index, pos in enumerate(indices):
res[pos] = s[index]
return ''.join(res)

Reference

  1. https://leetcode.com/problems/shuffle-string/
如果有收获,可以请我喝杯咖啡!