lintcode 试题记录
来源:互联网 发布:大数据时代的重要性 编辑:程序博客网 时间:2024/06/05 15:42
设计一种方法,将一个字符串中的所有空格替换成 %20
。你可以假设该字符串有足够的空间来加入新的字符,且你得到的是“真实的”字符长度。
class Solution {
public:/**
* @param string: An array of Char
* @param length: The true length of the string
* @return: The true length of new string
*/
int replaceBlank(char string[], int length) {
// Write your code here
for(int i = 0;i < length; i++)
{ if(string[i] == ' ')
{ for(int j = length+2; j > i+2; j--)
{ string[j] = string[j-2]; }
string[i] = '%';
string[i+1] = '2';
string[i+2] = '0';
i=i+2;
length = length+2;
}
}
return length;
}
};
为什么string长度可变?
0 0
- lintcode 试题记录
- LintCode实战记录
- LintCode 解题记录17.4.27
- LintCode解题记录17.4.28
- LintCode解题记录 17.5.3
- LintCode 解题记录 2017.6.3
- LintCode 解题记录 7.11 ~ 7.16
- LintCode 解题记录 Matrix专题
- LintCode解题记录17.9.9
- LintCode解题记录-Catalan Number
- LintCode 解体记录 17.9.26
- LintCode 解题记录17.10.21
- LintCode 解题记录 17.11.11
- LintCode 解题记录 17.5.15 (tag: 哈希表)
- LintCode 解题记录 17.5.22 (tag: Array)
- LintCode 解题记录 Array 17.6.5
- LintCode 解题记录 17.6.19~17.6.25
- LintCode 解题记录17.6.26 ~ 17.7.2
- 线程同步:互斥量与读写锁的异同与性能分析
- Java的类加载
- mysql日志介绍
- 杭电OJ-2072_单词数
- 实现iOS 8 Safari可伸缩的NavigationBar
- lintcode 试题记录
- Codeforces 463 E 乱搞
- hdu2829 Lawrence
- 实现抽取java中的注释的代码
- 数组中的逆序对
- Codeforces 466E LCA+搞
- mysql防止重复插入相同记录 insert if not exists
- tomcat中文乱码解决方案
- mysql常见错误