当前位置:网站首页>来n遍剑指--05. 替换空格
来n遍剑指--05. 替换空格
2022-07-31 08:57:00 【秦 羽】
专栏前言:
本专栏主要是算法训练,目的很简单。在掌握基本的java知识后,学习最重要的算法知识,在学习之前首先要对自身有一定的理解,如果不知道怎么做欢迎来私聊。
算法的过程很枯燥,但是也很特别,不断地刷题,不断地分享才会越来越好,给别人讲明白才是真正学会了。在分享中学会知识。
坚持就是胜利~~~
题目描述:
请实现一个函数,把字符串 s 中的每个空格替换成"%20"。
示例:
输入:s = "We are happy."
输出:"We%20are%20happy."
限制:
0 <= s 的长度 <= 10000
解题1:
创建新的String,如果有空格直接将%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();
}
}
课后习题:
休息休息啦

边栏推荐
- MUI获取相机权限
- 全国中职网络安全B模块之国赛题远程代码执行渗透测试 PHPstudy的后门漏洞分析
- Linux 创建mysql数据库并创建账号密码
- [MySQL exercises] Chapter 3 Common data types in MySQL
- 如何使用mysql binlog 恢复数据
- 剑指offer-解决面试题的思路
- Aleo Testnet3规划大纲
- Small application project development, jingdong mall 】 【 uni - app custom search component (below) - search history
- SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
- 【云原生与5G】微服务加持5G核心网
猜你喜欢

A brief introduction to the SSM framework
![[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket](/img/7b/f50c5f4b16a376273ba8cd27543676.png)
[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket

基于学生成绩管理系统(附源代码及数据库)

【Unity】编辑器扩展-03-拓展Inspector视图

【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议

蚂蚁核心科技产品亮相数字中国建设峰会 持续助力企业数字化转型

文件管理:目录管理

安装gnome-screenshot截图工具

六、MFC文档类(单文档和多文档)

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!
随机推荐
Modular specifications
我的创作纪念日
[MySQL exercises] Chapter 4 · Explore operators in MySQL with kiko
【黄啊码】MySQL入门—3、我用select ,老板直接赶我坐火车回家去,买的还是站票
2022杭电杯超级联赛3
关于@Autowired
The torch distributed training
JSP page对象简介说明
(selenium)Service geckodriver unexpectedly exited. Status code was: 64
高并发高可用高性能的解决方案
Which strings will be parsed as null by FastJson?
[Cloud native] Introduction and use of Feign of microservices
ecshop安装的时候提示不支持JPEG格式
@RequestBody和@RequestParam区别
【pytorch记录】pytorch的分布式 torch.distributed.launch 命令在做什么呢
35-Jenkins-Shared library application
【Redis高手修炼之路】Jedis——Jedis的基本使用
第八章 、接口
如何升级nodejs版本
How on one machine (Windows) to install two MYSQL database