02:替换空格

2019-07-30  本文已影响0人  iwtbam

题目描述

解题思路

AC代码

class Solution {
public:
    void replaceSpace(char *str,int length) {
        char* aux = (char*)malloc(length);
        const char* s = "%20";
        for(int i = 0; i< length; i++)
            aux[i] = str[i];
        
        int p1 = 0, p2 = 0;
        while(p1 < length)
        {
            if(aux[p1] == ' ')
            {
               for(int i = 0; i < 3; i++)
                   str[p2++] = s[i];
            }
            else
                str[p2++] = aux[p1];
            p1++;
        }
    }
};
上一篇下一篇

猜你喜欢

热点阅读