当前位置:网站首页>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;
}
}
边栏推荐
- Chapter 6 data flow modeling - after class exercises
- [binary search] 69 Square root of X
- 【Jailhouse 文章】Look Mum, no VM Exits
- High precision subtraction
- YOLOv5添加注意力機制
- Reflection summary of Haut OJ freshmen on Wednesday
- 二十六、文件系统API(设备在应用间的共享;目录和文件API)
- The present is a gift from heaven -- a film review of the journey of the soul
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
猜你喜欢
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
The present is a gift from heaven -- a film review of the journey of the soul
Reader writer model
National teacher qualification examination in the first half of 2022
[turn]: OSGi specification in simple terms
[speed pointer] 142 circular linked list II
[to be continued] [depth first search] 547 Number of provinces
Pointnet++学习
YOLOv5添加注意力機制
剑指 Offer 53 - II. 0~n-1中缺失的数字
随机推荐
C language Essay 1
kubeadm系列-02-kubelet的配置和启动
National teacher qualification examination in the first half of 2022
[to be continued] [UE4 notes] L3 import resources and project migration
Haut OJ 1401: praise energy
Double pointer Foundation
Haut OJ 1241: League activities of class XXX
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
Summary of Haut OJ 2021 freshman week
MySQL数据库(一)
kubeadm系列-01-preflight究竟有多少check
用STM32点个灯
对象的序列化
服务熔断 Hystrix
质量体系建设之路的分分合合
The number of enclaves
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
过拟合与正则化
[speed pointer] 142 circular linked list II
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution