当前位置:网站首页>剑指 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;
}
}
边栏推荐
- room数据库的使用
- Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
- kubeadm系列-02-kubelet的配置和启动
- JVM call not used once in ten years
- Research on the value of background repeat of background tiling
- The next key of win generates the timestamp file of the current day
- 64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
- A new micro ORM open source framework
- Haut OJ 1350: choice sends candy
- Haut OJ 1218: maximum continuous sub segment sum
猜你喜欢

2022年上半年国家教师资格证考试

Pointnet++学习

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

Learning notes of "hands on learning in depth"

sync.Mutex源码解读
![[turn to] MySQL operation practice (I): Keywords & functions](/img/b1/8b843014f365b786e310718f669043.png)
[turn to] MySQL operation practice (I): Keywords & functions

GBase数据库助力湾区数字金融发展

Optimization scheme of win10 virtual machine cluster

远程升级怕截胡?详解FOTA安全升级

Web APIs DOM节点
随机推荐
Talking about JVM (frequent interview)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
使用命令符关闭笔记本自带键盘命令
Simple modal box
kubeadm系列-01-preflight究竟有多少check
Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
[to be continued] [UE4 notes] L3 import resources and project migration
sync.Mutex源码解读
[depth first search] 695 Maximum area of the island
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
[binary search] 69 Square root of X
一个新的微型ORM开源框架
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
A new micro ORM open source framework
C语言杂谈1
JVM call not used once in ten years
Summary of Haut OJ 2021 freshman week
Haut OJ 1352: string of choice
kubeadm系列-02-kubelet的配置和启动
Add level control and logger level control of Solon logging plug-in