class Solution {
public:
string restoreString(string s, vector<int>& indices) {
string temp = s;
for(int i = 0; i < indices.size(); i++)
{
char c = s[i];
s[i] = temp[indices[i]];
temp[indices[i]] = c;
}
return temp;
}
};
或者是
class Solution {
public:
string restoreString(string s, vector<int>& indices) {
string temp = s;
for(int i = 0; i < indices.size(); i++)
{
swap(s[i], temp[indices[i]]);
}
return temp;
}
};