LeetCode替换空格:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/submissions/
class Solution {
public:
void replaceSpace(char str[],int length) {
if(length == 0 || str == nullptr) return;
int original = 0,number_blank = 0,k = 0;
while(str[k] != '\0')
{
original ++; //
if( str[k] == ' ') number_blank ++;
k ++;
}
int new_length = original + number_blank * 2;
int i = original,j = new_length;
while(i >= 0 && j > i)
{
if(str[i] == ' ')
{
str[ j -- ] = '0';
str[j --] = '2';
str[j --] = '%';
}
else str[j--] = str[i];
i --;
}
}
};
https://leetcode-cn.com/problems/lru-cache-lcci/
来源:https://www.nowcoder.com/discuss/416670