当前位置:网站首页>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;
}
}
边栏推荐
- [轉]: OSGI規範 深入淺出
- lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
- 服务熔断 Hystrix
- Palindrome (csp-s-2021-palin) solution
- Introduction to tools in TF-A
- Haut OJ 1221: a tired day
- YOLOv5-Shufflenetv2
- Service fusing hystrix
- Alu logic operation unit
- Binary search basis
猜你喜欢
随机推荐
[turn to] MySQL operation practice (III): table connection
kubeadm系列-01-preflight究竟有多少check
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
对象的序列化
剑指 Offer 06.从头到尾打印链表
[to be continued] [depth first search] 547 Number of provinces
MySQL数据库(一)
剑指 Offer 53 - II. 0~n-1中缺失的数字
Insert sort
[转]MySQL操作实战(三):表联结
Development error notes
Introduction to tools in TF-A
使用Electron开发桌面应用
Solon Auth 认证框架使用演示(更简单的认证框架)
FVP和Juno平台的Memory Layout介绍
每日一题-搜索二维矩阵ps二维数组的查找
To the distance we have been looking for -- film review of "flying house journey"
Haut OJ 1241: League activities of class XXX
kubeadm系列-02-kubelet的配置和启动
Haut OJ 1401: praise energy