题目描述
# -*- coding:utf-8 -*-
class Solution:
# s 源字符串
def replaceSpace(self, s):
# write code here
return "%20".join(list(s.split(" ")))
public class Solution {
public String replaceSpace(StringBuffer str) {
StringBuffer out=new StringBuffer();
for (int i=0;i<str.toString().length();i++){
char b=str.charAt(i);
if (String.valueOf(b).equals(" ")){
out.append("%20");
}else {
out.append(b);
}
}
return out.toString();
}
}
class Solution {
public:
void replaceSpace(char *str,int length) {
int count=0;
for (int i=0;i<length;i++){
if (str[i]==' ')
count++;
}
for (int i=length-1;i>=0;i--){
if (str[i]!=' ')
{
str[i+2*count]=str[i];
}
else {
count--;
str[i+2*count]='%';
str[i+2*count+1]='2';
str[i+2*count+2]='0';
}
}
}
};