当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

Using HashMap to realize simple cache

Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade

剑指 Offer 06.从头到尾打印链表

TF-A中的工具介绍

National teacher qualification examination in the first half of 2022

Solution to the palindrome string (Luogu p5041 haoi2009)

Shell Sort
![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
[轉]: OSGI規範 深入淺出

剑指 Offer 09. 用两个栈实现队列

剑指 Offer 05. 替换空格
随机推荐
记录QT内存泄漏的一种问题和解决方案
[转]:Apache Felix Framework配置属性
过拟合与正则化
The number of enclaves
Reader writer model
使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
Haut OJ 1241: League activities of class XXX
剑指 Offer 53 - I. 在排序数组中查找数字 I
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
GBase数据库助力湾区数字金融发展
Double pointer Foundation
Merge sort
[转]: OSGI规范 深入浅出
26、 File system API (device sharing between applications; directory and file API)
对象的序列化
[interval problem] 435 Non overlapping interval
Haut OJ 1401: praise energy
剑指 Offer 53 - II. 0~n-1中缺失的数字
High precision subtraction
[turn to] MySQL operation practice (I): Keywords & functions