[LeetCode C++实现]1528. Shuffle String
常规解法,空间复杂度时间复杂度O(n)
class Solution {
public:
string restoreString(string s, vector<int>& indices) {
string res(s);
int n = s.size();
for(int i = 0;i < n;i++)
{
res[indices[i]] = s[i];
}
return res;
}
};
运行结果:
Runtime: 8 ms, faster than 98.74% of C++ online submissions for Shuf......