题目:替换空格
要求:请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
1 class Solution { 2 public: 3 void replaceSpace(char *str,int length) { 4 5 } 6 };
解题代码:
1 class Solution { 2 public: 3 void replaceSpace(char *str,int length) { 4 if(str == nullptr || length <= 0) 5 return ; 6 7 int origLength = 0; 8 int numBlank = 0; 9 int i = 0; 10 while(str[i] != '