当前位置:网站首页>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;
}
}
边栏推荐
- Use of room database
- 全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
- xftp7与xshell7下载(官网)
- 剑指 Offer 09. 用两个栈实现队列
- What is the agile proportion of PMP Exam? Dispel doubts
- Software test -- 0 sequence
- 剑指 Offer 05. 替换空格
- Educational Codeforces Round 107 (Rated for Div. 2) E. Colorings and Dominoes
- Haut OJ 1221: a tired day
- C language Essay 1
猜你喜欢
Chapter 6 data flow modeling - after class exercises
Romance of programmers on Valentine's Day
[speed pointer] 142 circular linked list II
Double pointer Foundation
YOLOv5-Shufflenetv2
Count sort
[merge array] 88 merge two ordered arrays
第六章 数据流建模—课后习题
To the distance we have been looking for -- film review of "flying house journey"
Gbase database helps the development of digital finance in the Bay Area
随机推荐
Control Unit 控制部件
剑指 Offer 53 - I. 在排序数组中查找数字 I
sync.Mutex源码解读
Under the national teacher qualification certificate in the first half of 2022
Drawing dynamic 3D circle with pure C language
[转]MySQL操作实战(一):关键字 & 函数
Programmers' experience of delivering takeout
Talking about JVM (frequent interview)
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
Time complexity and space complexity
过拟合与正则化
第六章 数据流建模—课后习题
每日一题-无重复字符的最长子串
[to be continued] [UE4 notes] L2 interface introduction
SAP-修改系统表数据的方法
The number of enclaves
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
Codeforces Round #715 (Div. 2) D. Binary Literature