当前位置:网站首页>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;
}
}
边栏推荐
- Add level control and logger level control of Solon logging plug-in
- Haut OJ 2021 freshmen week II reflection summary
- Mysql database (I)
- 远程升级怕截胡?详解FOTA安全升级
- 用STM32点个灯
- Haut OJ 1357: lunch question (I) -- high precision multiplication
- The number of enclaves
- MySQL数据库(一)
- GBase数据库助力湾区数字金融发展
- [binary search] 34 Find the first and last positions of elements in a sorted array
猜你喜欢
随机推荐
Developing desktop applications with electron
用STM32点个灯
Control Unit 控制部件
Acwing 4301. Truncated sequence
注解与反射
【Jailhouse 文章】Look Mum, no VM Exits
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
Haut OJ 1245: large factorial of CDs --- high precision factorial
GBase数据库助力湾区数字金融发展
剑指 Offer 53 - II. 0~n-1中缺失的数字
[转]MySQL操作实战(三):表联结
服务熔断 Hystrix
SAP-修改系统表数据的方法
Yolov5 adds attention mechanism
[turn]: OSGi specification in simple terms
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
PC寄存器
On-off and on-off of quality system construction
kubeadm系列-00-overview
剑指 Offer 09. 用两个栈实现队列




![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)


![[转]MySQL操作实战(一):关键字 & 函数](/img/b1/8b843014f365b786e310718f669043.png)

