close

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.

解題: 給一字串與一數字陣列,要求將字串以數字陣列順序重構 按照要求直覺進行coding python code:

class Solution:
    def restoreString(self, s: str, indices: List[int]) -> str:
        dicts={}
        for i,j in zip(s,indices):
            dicts[j]=i
        correct=[]
        for a in range(len(indices)):
            correct.append(dicts[a])
        return "".join(s for s in correct)

arrow
arrow
    文章標籤
    leetcode python
    全站熱搜
    創作者介紹
    創作者 低階ㄇㄋ 的頭像
    低階ㄇㄋ

    蟲匯聚之所

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()