C++
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return string字符串
*/
string replaceSpace(string s) {
// write code here
int n =s.size();
string r;
for(int i=0;i<n;i++){
if(s[i]==' ')
r+=s[i];
else
r+="%20";
}
return r;
}
};
不能直接把‘%20’赋值。真的是好久没打代码啥都不记得了。
Python
class Solution:
def replaceSpace(self , s ):
# write code here
return s.replace(" ","%20")
到底是用一种语言好一点还是哪个方便用哪个呢。