当前位置:网站首页>剑指 Offer 05. 替换空格
剑指 Offer 05. 替换空格
2022-07-05 05:26:00 【ThE wAlkIng D】
题目描述

问题解析
1.使用数组来做,首先将新建一个数组,计算原始字符串的长度当做数组长度
2.遍历数组。找到空格字符串,提换为“%20”;
3.新数组建立原来数组长度的三倍,用来存放新字符串
4.字符串数组转为字符串
5.考察.charAt的用法,以及字符数组转为字符串的用法(String a =new String())
代码实例
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 1241: League activities of class XXX
- C语言杂谈1
- Romance of programmers on Valentine's Day
- Chapter 6 data flow modeling - after class exercises
- SDEI初探-透过事务看本质
- National teacher qualification examination in the first half of 2022
- 对象的序列化
- Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
- kubeadm系列-00-overview
- Haut OJ 1245: large factorial of CDs --- high precision factorial
猜你喜欢

小程序直播+电商,想做新零售电商就用它吧!

Gbase database helps the development of digital finance in the Bay Area

Optimization scheme of win10 virtual machine cluster

Embedded database development programming (zero)

sync.Mutex源码解读

小程序直播+電商,想做新零售電商就用它吧!
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

Learning notes of "hands on learning in depth"
![[to be continued] [depth first search] 547 Number of provinces](/img/c4/b4ee3d936776dafc15ac275d2059cd.jpg)
[to be continued] [depth first search] 547 Number of provinces
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)
[to be continued] [UE4 notes] L1 create and configure items
随机推荐
[trans]: spécification osgi
kubeadm系列-02-kubelet的配置和启动
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Solon Auth 认证框架使用演示(更简单的认证框架)
kubeadm系列-00-overview
The present is a gift from heaven -- a film review of the journey of the soul
To be continued] [UE4 notes] L4 object editing
Solon 框架如何方便获取每个请求的响应时间?
xftp7与xshell7下载(官网)
服务熔断 Hystrix
C language Essay 1
PMP考生,请查收7月PMP考试注意事项
记录QT内存泄漏的一种问题和解决方案
Yolov5 ajouter un mécanisme d'attention
第六章 数据流建模—课后习题
Reflection summary of Haut OJ freshmen on Wednesday
[转]: OSGI规范 深入浅出
room数据库的使用
To the distance we have been looking for -- film review of "flying house journey"
使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor