当前位置:网站首页>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;
}
}
边栏推荐
- SSH password free login settings and use scripts to SSH login and execute instructions
- Yolov5 ajouter un mécanisme d'attention
- Palindrome (csp-s-2021-palin) solution
- 剑指 Offer 58 - II. 左旋转字符串
- 剑指 Offer 06.从头到尾打印链表
- sync. Interpretation of mutex source code
- [sum of two numbers] 169 sum of two numbers II - enter an ordered array
- [speed pointer] 142 circular linked list II
- [interval problem] 435 Non overlapping interval
- Gbase database helps the development of digital finance in the Bay Area
猜你喜欢
随机推荐
[depth first search] 695 Maximum area of the island
The present is a gift from heaven -- a film review of the journey of the soul
[binary search] 34 Find the first and last positions of elements in a sorted array
Download xftp7 and xshell7 (official website)
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
After setting up the database and website When you open the app for testing, it shows that the server is being maintained
[binary search] 69 Square root of X
质量体系建设之路的分分合合
Pointnet++ learning
Csp-j-2020-excellent split multiple solutions
xftp7与xshell7下载(官网)
Detailed explanation of expression (csp-j 2021 expr) topic
[speed pointer] 142 circular linked list II
Shell Sort
Summary of Haut OJ 2021 freshman week
Haut OJ 1357: lunch question (I) -- high precision multiplication
二十六、文件系统API(设备在应用间的共享;目录和文件API)
Demonstration of using Solon auth authentication framework (simpler authentication framework)
26、 File system API (device sharing between applications; directory and file API)