当前位置:网站首页>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;
}
}
边栏推荐
- Haut OJ 1350: choice sends candy
- xftp7与xshell7下载(官网)
- Detailed explanation of expression (csp-j 2021 expr) topic
- kubeadm系列-01-preflight究竟有多少check
- kubeadm系列-02-kubelet的配置和启动
- FVP和Juno平台的Memory Layout介绍
- Programmers' experience of delivering takeout
- Count sort
- 剑指 Offer 58 - II. 左旋转字符串
- Haut OJ 1357: lunch question (I) -- high precision multiplication
猜你喜欢
支持多模多态 GBase 8c数据库持续创新重磅升级
Gbase database helps the development of digital finance in the Bay Area
剑指 Offer 06.从头到尾打印链表
Introduction to tools in TF-A
Fragment addition failed error lookup
[to be continued] [UE4 notes] L1 create and configure items
剑指 Offer 04. 二维数组中的查找
Double pointer Foundation
游戏商城毕业设计
Yolov5 ajouter un mécanisme d'attention
随机推荐
YOLOv5-Shufflenetv2
[speed pointer] 142 circular linked list II
Heap sort summary
Introduction to memory layout of FVP and Juno platforms
使用Electron开发桌面应用
Insert sort
Download xftp7 and xshell7 (official website)
服务熔断 Hystrix
object serialization
Haut OJ 1218: maximum continuous sub segment sum
After setting up the database and website When you open the app for testing, it shows that the server is being maintained
Chapter 6 data flow modeling - after class exercises
Control Unit 控制部件
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
[turn to] MySQL operation practice (III): table connection
常见的最优化方法
2022上半年全国教师资格证下
[merge array] 88 merge two ordered arrays
Binary search basis
Haut OJ 1243: simple mathematical problems