当前位置:网站首页>string replace spaces
string replace spaces
2022-07-30 00:17:00 【Ryuzaki Liuhe】
Title:
Please implement a function that replaces each space in the string s with "%20".
Example 1:
Input: s = “We are happy.”
Output: “We%20are%20happy.”
Analysis:
Because String typeImmutable, so StringBuilder is needed to recreate a String back.
Code:
public class ReplaceSpace {public String replaceSpace(String s) {StringBuilder stringBuilder = new StringBuilder();for (int i = 0; i <s.length(); i++) {if (s.charAt(i) == ' '){stringBuilder.append("%20");}else {stringBuilder.append(s.charAt(i));}}return stringBuilder.toString();}}
边栏推荐
猜你喜欢
MySQL 用 BETWEEN AND 日期查询包含范围边界
Getting Started with Sentinel
Recurrent Neural Network (RNN)
Docker install MySQL8.0
EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
Low dropout linear regulator MPQ2013A-AEC1 brand MPS domestic replacement
Reading notes. This is the psychology: see through the essence of the pseudo psychology (version 10)"
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
Mysql internal and external connections
Worthington优化技术:细胞定量
随机推荐
旋转数组的最小数字
Unity Addressables
Graph Theory: Bipartite Graphs
[Experience] Experience Summary - Lessons Learned
Weekly recommended short video: What is R&D efficiency?It can achieve anti "involution"?
Go日志库——logrus
Worthington Optimized Technology: Cell Quantification
『牛客|每日一题』走迷宫
The basic parallel I/O port of single chip microcomputer development
News text classification
Worthington经过使用测试的细胞分离系统方案
YOLO数据格式说明与转换
MySQL 用 BETWEEN AND 日期查询包含范围边界
关于MySQL索引的一些个人理解(部分参考MySQL45讲)
Worthington用于细胞收获的胰蛋白酶&细胞释放程序
WeChat developer tools set the tab size to 2
Chinese semantic matching
关于 byte 的范围
try_catch捕获异常
【mysql】Mysql公用表表达式with as