当前位置:网站首页>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;
}
}
边栏推荐
- Csp-j-2020-excellent split multiple solutions
- kubeadm系列-01-preflight究竟有多少check
- Web APIs DOM node
- Haut OJ 1241: League activities of class XXX
- 注解与反射
- A new micro ORM open source framework
- [interval problem] 435 Non overlapping interval
- 【Jailhouse 文章】Look Mum, no VM Exits
- Romance of programmers on Valentine's Day
- 第六章 数据流建模—课后习题
猜你喜欢

浅谈JVM(面试常考)

sync.Mutex源码解读
![[转]: OSGI规范 深入浅出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[转]: OSGI规范 深入浅出

The present is a gift from heaven -- a film review of the journey of the soul

Little known skills of Task Manager
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

Chapter 6 data flow modeling - after class exercises

第六章 数据流建模—课后习题

Bucket sort

To the distance we have been looking for -- film review of "flying house journey"
随机推荐
剑指 Offer 53 - II. 0~n-1中缺失的数字
第六章 数据流建模—课后习题
Development error notes
xftp7与xshell7下载(官网)
Use of room database
[转]: OSGI规范 深入浅出
Haut OJ 1243: simple mathematical problems
读者写者模型
2022年上半年国家教师资格证考试
Csp-j-2020-excellent split multiple solutions
[to be continued] [UE4 notes] L1 create and configure items
剑指 Offer 04. 二维数组中的查找
使用Electron开发桌面应用
【ES实战】ES上的native realm安全方式使用
Solon Logging 插件的添加器级别控制和日志器的级别控制
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
记录QT内存泄漏的一种问题和解决方案
[binary search] 34 Find the first and last positions of elements in a sorted array
卷积神经网络——卷积层
Fragment addition failed error lookup