class Solution {
public:
string replaceSpaces(string &str) {
int len = str.size();
int i = 0;
while(i<str.size()){
if(str[i] == ' '){
string substr1 = str.substr(0,i);
string substr2 = "%20";
string substr3 = str.substr(i+1);
str = substr1+substr2+substr3;
i += 2;
}
i+=1;
}
return str;
}
};