标签:
class Solution { public: void replaceSpace(char *str, int length) { int spaceNum = 0; for(int i = 0; i < length; ++i) { if(str[i] == ‘ ‘) ++spaceNum; } int newIndex = length + 2 * spaceNum - 1; int index = length - 1; while(index >= 0) { if(str[index] == ‘ ‘) { str[newIndex--] = ‘0‘; str[newIndex--] = ‘2‘; str[newIndex--] = ‘%‘; } else str[newIndex--] = str[index]; index--; } } };
标签:
原文地址:http://www.cnblogs.com/xuyan505/p/5354080.html