当前位置:网站首页>Come n times with the sword--05. Replace spaces
Come n times with the sword--05. Replace spaces
2022-07-31 09:20:00 【Qin feather】
专栏前言:
本专栏主要是算法训练,目的很简单.在掌握基本的java知识后,学习最重要的算法知识,在学习之前首先要对自身有一定的理解,如果不知道怎么做欢迎来私聊.
算法的过程很枯燥,但是也很特别,不断地刷题,不断地分享才会越来越好,给别人讲明白才是真正学会了.在分享中学会知识.
坚持就是胜利~~~
题目描述:
请实现一个函数,把字符串 s 中的每个空格替换成"%20".
示例:
输入:s = "We are happy."
输出:"We%20are%20happy."
限制:
0 <= s 的长度 <= 10000
解题1:
创建新的String,If there is a space, it will be directly%20加入到string
class Solution {
public String replaceSpace(String s) {
if(s == null){
return null;
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < s.length(); i++){
if(s.charAt(i) == ' '){
sb.append("%20");
}else{
sb.append(s.charAt(i));
}
}
return sb.toString();
}
}
课后习题:
rest

边栏推荐
猜你喜欢

win10镜像下载

js右侧圆点单页滚动介绍页面

【TCP/IP】Network Model

零代码工具推荐 八爪鱼采集器

【问题记录】TypeError: eval() arg 1 must be a string, bytes or code object

Are postgresql range queries faster than index queries?

loadrunner脚本--添加集合点

SSM integration case study (detailed)

I advise those juniors and juniors who have just started working: If you want to enter a big factory, you must master these core skills!Complete Learning Route!

混合型界面:对话式UI的未来
随机推荐
MySQL (2)
loadrunner脚本--添加检查点
matlab常用符号用法总结
A Spark SQL online problem troubleshooting and positioning
OpenGL es 初识
Kotlin—基本语法(三)
来n遍剑指--09. 用两个栈实现队列
多版本node的安装与切换详细操作
loadrunner脚本--添加集合点
【TCP/IP】网络模型
Kotlin—基本语法 (四)
(selenium)Service geckodriver unexpectedly exited. Status code was: 64
Define event types in Splunk Web
安装gnome-screenshot截图工具
Kotlin—基本语法 (五)
How to restore data using mysql binlog
Which strings will be parsed as null by FastJson?
高并发高可用高性能的解决方案
51单片机-----外部中断
文件管理:目录管理