Leetcode 1528. Shuffle String 用哈希表做

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

你可能感兴趣的:(算法)