当前位置:网站首页>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;
}
}
边栏推荐
- 质量体系建设之路的分分合合
- 剑指 Offer 53 - I. 在排序数组中查找数字 I
- Solon 框架如何方便获取每个请求的响应时间?
- 利用HashMap实现简单缓存
- 使用Electron开发桌面应用
- Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
- Gbase database helps the development of digital finance in the Bay Area
- Programmers' experience of delivering takeout
- 支持多模多态 GBase 8c数据库持续创新重磅升级
- Acwing 4300. Two operations
猜你喜欢
随机推荐
Zzulioj 1673: b: clever characters???
剑指 Offer 35.复杂链表的复制
过拟合与正则化
剑指 Offer 05. 替换空格
[to be continued] [depth first search] 547 Number of provinces
Hang wait lock vs spin lock (where both are used)
卷积神经网络——卷积层
剑指 Offer 09. 用两个栈实现队列
C language Essay 1
剑指 Offer 53 - I. 在排序数组中查找数字 I
What is the agile proportion of PMP Exam? Dispel doubts
To the distance we have been looking for -- film review of "flying house journey"
The present is a gift from heaven -- a film review of the journey of the soul
服务熔断 Hystrix
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
Control Unit 控制部件
PMP candidates, please check the precautions for PMP examination in July
[to be continued] [UE4 notes] L2 interface introduction
Bucket sort
Fragment addition failed error lookup