从前向后记录空格数目,从后向前替换空格 class Solution { public: void replaceSpace(char *str,int length) { // edge case if(str == nullptr || length == 0) return; // 统计空格数量 int count = 0; for(int i=0; i<length; i++){ if(str[i] == ' ') count++; } // 倒序写入字符 for(int i=length-1; i>=0; i--){ if(str[i] != ' '){ str[i+2*...