当前位置:网站首页>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;
}
}
边栏推荐
- Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
- [转]MySQL操作实战(三):表联结
- Development error notes
- [trans]: spécification osgi
- A misunderstanding about the console window
- Solon Auth 认证框架使用演示(更简单的认证框架)
- Detailed explanation of expression (csp-j 2021 expr) topic
- YOLOv5-Shufflenetv2
- Haut OJ 1241: League activities of class XXX
- kubeadm系列-00-overview
猜你喜欢
随机推荐
ALU逻辑运算单元
Romance of programmers on Valentine's Day
Haut OJ 1243: simple mathematical problems
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Web APIs DOM节点
What is the agile proportion of PMP Exam? Dispel doubts
YOLOv5-Shufflenetv2
High precision subtraction
object serialization
[转]:Apache Felix Framework配置属性
room数据库的使用
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
[speed pointer] 142 circular linked list II
[转]MySQL操作实战(三):表联结
Solon Logging 插件的添加器级别控制和日志器的级别控制
A problem and solution of recording QT memory leakage
Palindrome (csp-s-2021-palin) solution
Control Unit 控制部件
Codeforces Round #715 (Div. 2) D. Binary Literature
[allocation problem] 455 Distribute cookies