标签:
提交时间:2015-09-25 语言:C++ 运行时间:0ms 占用内存:11144K 状态:答案正确 //此方法占用内存较大! class Solution { public: void replaceSpace(char *str,int length) { if (str == NULL || length <= 0) return ; char *stemp = new char[3*length+1]; int j = 0; for (int i = 0; i < length; i++){ if (str[i] == ‘ ‘){ stemp[j] = ‘%‘; stemp[j+1] = ‘2‘; stemp[j+2] = ‘0‘; j += 3; } else stemp[j++] = str[i]; } stemp[j] = ‘\0‘; for (int i = 0; i <= j; i++) str[i] = stemp[i]; } };
标签:
原文地址:http://www.cnblogs.com/qianmacao/p/4839487.html