当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
随机推荐
【Jailhouse 文章】Look Mum, no VM Exits
Gbase database helps the development of digital finance in the Bay Area
卷积神经网络——卷积层
剑指 Offer 53 - I. 在排序数组中查找数字 I
[转]MySQL操作实战(三):表联结
MySQL数据库(一)
Talking about JVM (frequent interview)
Fragment addition failed error lookup
Haut OJ 1316: sister choice buys candy III
Pointnet++的改进
[转]MySQL操作实战(一):关键字 & 函数
[to be continued] [UE4 notes] L1 create and configure items
Bucket sort
剑指 Offer 06.从头到尾打印链表
Csp-j-2020-excellent split multiple solutions
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
kubeadm系列-02-kubelet的配置和启动
Web APIs DOM节点
ssh免密登录设置及使用脚本进行ssh登录并执行指令
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization



![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)

![To be continued] [UE4 notes] L4 object editing](/img/0f/cfe788f07423222f9eed90f4cece7d.jpg)
![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)


