逆向思维
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return string字符串
*/
string replaceSpace(string s) {
// write code here
int Len=s.size();
int pos=Len-1;
while( string::npos!=s.rfind( ' ', pos ) )
{
int num=s.rfind( ' ', pos );
s.replace( num, 1, "%20" );
pos=num;
}
return s;
}
}; 
京公网安备 11010502036488号