Leetcode 1528. Shuffle String

2022-05-10 08:02:03 浏览数 (1)

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

1. Description

2. Solution

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

  • Version 1
代码语言:javascript复制
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/

0 人点赞