class Solution {
public:
string replaceSpaces(string &str) {
if(str == " ")
return str;
int count = 0;
for(auto& m : str)
if(m == ' ') ++count;
int n = str.size();
str.resize(str.size() + 2*count);
for(int i = n - 1; i >= 0; --i)
{
if(str[i] != ' ')
str[i+count*2] = str[i];
else
{
str[i + count*2] = '0';
str[i + count*2 - 1] = '2';
str[i + count*2 - 2] = '%';
--count;
}
}
return str;
}
};