当前位置:网站首页>Sword finger offer 05 Replace spaces
Sword finger offer 05 Replace spaces
2022-07-05 05:29:00 【ThE wAlkIng D】
Title Description

Problem analysis
1. Use arrays to do , First, create an array , Calculate the length of the original string as the length of the array
2. Traversal array . Space string found , Replace it with “%20”;
3. The new array builds three times the length of the original array , Used to store new strings
4. String array to string
5. Investigate .charAt Usage of , And the use of converting character arrays into strings (String a =new String())
Code instance
class Solution {
public String replaceSpace(String s) {
int len = s.length();
int[] s1 = new int[3*n];
int j = 0;
for(int i = 0;i < n;i++){
if(s.charAt(i) == ' '){
s1[j++] = "%";
s1[j++] = "2";
s1[j++] = "0";
}
else{
s1[j++] = s.chaAt(i);
}
}
String newStr = new String(s1,0,j);
return newStr;
}
}
边栏推荐
- 浅谈JVM(面试常考)
- 剑指 Offer 04. 二维数组中的查找
- 【ES实战】ES上的native realm安全方式使用
- [转]:Apache Felix Framework配置属性
- Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
- Download xftp7 and xshell7 (official website)
- 剑指 Offer 58 - II. 左旋转字符串
- sync.Mutex源码解读
- Zzulioj 1673: b: clever characters???
- 剑指 Offer 53 - II. 0~n-1中缺失的数字
猜你喜欢

sync. Interpretation of mutex source code

To the distance we have been looking for -- film review of "flying house journey"
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)
[merge array] 88 merge two ordered arrays

服务熔断 Hystrix
![[turn]: OSGi specification in simple terms](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[turn]: OSGi specification in simple terms

GBase数据库助力湾区数字金融发展

Web APIs DOM节点

Web APIs DOM node
随机推荐
[speed pointer] 142 circular linked list II
[to be continued] [UE4 notes] L1 create and configure items
[interval problem] 435 Non overlapping interval
[binary search] 69 Square root of X
Fragment addition failed error lookup
Drawing dynamic 3D circle with pure C language
MySQL数据库(一)
浅谈JVM(面试常考)
[转]MySQL操作实战(一):关键字 & 函数
Introduction to tools in TF-A
游戏商城毕业设计
Haut OJ 1245: large factorial of CDs --- high precision factorial
sync.Mutex源码解读
Summary of Haut OJ 2021 freshman week
二十六、文件系统API(设备在应用间的共享;目录和文件API)
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
Haut OJ 1218: maximum continuous sub segment sum
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
[轉]: OSGI規範 深入淺出