当前位置:网站首页>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;
}
}
边栏推荐
- 二十六、文件系统API(设备在应用间的共享;目录和文件API)
- Count sort
- [轉]: OSGI規範 深入淺出
- [allocation problem] 455 Distribute cookies
- [to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
- YOLOv5-Shufflenetv2
- Software test -- 0 sequence
- How can the Solon framework easily obtain the response time of each request?
- 常见的最优化方法
- Haut OJ 1221: a tired day
猜你喜欢
随机推荐
Detailed explanation of expression (csp-j 2021 expr) topic
The number of enclaves
对象的序列化
Acwing 4301. Truncated sequence
过拟合与正则化
剑指 Offer 06.从头到尾打印链表
Csp-j-2020-excellent split multiple solutions
[to be continued] [depth first search] 547 Number of provinces
Reader writer model
质量体系建设之路的分分合合
SAP-修改系统表数据的方法
kubeadm系列-01-preflight究竟有多少check
剑指 Offer 05. 替换空格
Yolov5 adds attention mechanism
Binary search basis
Double pointer Foundation
剑指 Offer 04. 二维数组中的查找
YOLOv5-Shufflenetv2
Heap sort summary
Maximum number of "balloons"


![[turn]: OSGi specification in simple terms](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
![[转]MySQL操作实战(一):关键字 & 函数](/img/b1/8b843014f365b786e310718f669043.png)

![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)


