본문 바로가기
IT/알고리즘

42] Leetcode 1528. Shuffle String

by 깻잎쌈 2020. 8. 18.
반응형

https://leetcode.com/problems/shuffle-string/

 

Shuffle String - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

ans와 s는 길이가 같을 테니

초기값을 s로 하고 하나씩 바꾼다.

class Solution {
public:
    string restoreString(string s, vector<int>& indices) {
        string ans = s;
        for(int i = 0;i<indices.size();i++)
            ans[indices[i]] = s[i];
        
        return ans;
    }
};
반응형

댓글