剑指offer 替换空格
class Solution {
public:
void replaceSpace(char *str,int length) {
for(int i=0;i<length;i++)
{
if(str[i]== ) //如果存在空格
{
for(int j=length+1;j>=i+3;j--) //后面的元素向后移动两位
str[j]=str[j-2];
str[i] = %;
str[i+1] = 2;
str[i+2] = 0;
length+=2;
}
}
}
};
class Solution {
public:
void replaceSpace(char *str,int length) {
for(int i=0;i<length;i++)
{
if(str[i]== ) //如果存在空格
{
for(int j=length+1;j>=i+3;j--) //后面的元素向后移动两位
str[j]=str[j-2];
str[i] = %;
str[i+1] = 2;
str[i+2] = 0;
length+=2;
}
}
}
};
2020-04-30
在牛客打卡21天,今天学习:刷题 15 道/代码提交 14 次
全部评论
相关推荐
点赞 评论 收藏
分享