标签:tle else 剑指offer solution enter pes desc bsp space
class Solution { public: void replaceSpace(char *str,int length) { } };
做完看了下讨论的代码基本都是从后往前替换,也行但是这样就要扫两遍了
AC代码:
class Solution { public: void replaceSpace(char *str,int length) { char str2[1000]; int num = 0; for(int i = 0; i < length; i++) { if(str[i] == ‘ ‘) str2[num++] = ‘%‘, str2[num++] = ‘2‘, str2[num++] = ‘0‘; else str2[num++] = str[i]; } strcpy(str, str2); } };
标签:tle else 剑指offer solution enter pes desc bsp space
原文地址:https://www.cnblogs.com/Hyouka/p/9252978.html