当前位置:网站首页>Leetcode question brushing: String 03 (Sword finger offer 05. replace space)
Leetcode question brushing: String 03 (Sword finger offer 05. replace space)
2022-06-26 20:50:00 【Taotao can't learn English】
subject : The finger of the sword Offer 05. Replace blank space
Please implement a function , Put the string s Replace each space in with "%20".
Example 1:
Input :s = “We are happy.”
Output :“We%20are%20happy.”
It's easy to think about it , As long as you know the space Ascll Just a few yards . Once sent to the soul .
There's nothing to say .
package com.programmercarl.string;
/** * @ClassName ReplaceSpace * @Descriotion TODO * @Author nitaotao * @Date 2022/6/23 19:49 * @Version 1.0 * https://leetcode.cn/problems/ti-huan-kong-ge-lcof/ * The finger of the sword Offer 05. Replace blank space **/
public class ReplaceSpace {
public static void main(String[] args) {
// char space = ' ';
//32
// System.out.println(space - 0);
System.out.println(replaceSpace("We are happy."));
}
public static String replaceSpace(String s) {
char[] chars = s.toCharArray();
StringBuffer result = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == 32) {
result.append("%20");
} else {
result.append(chars[i]);
}
}
return String.valueOf(result);
}
}

边栏推荐
- 【贝叶斯分类2】朴素贝叶斯分类器
- 0基础c语言(0)
- C language file cursor fseek
- Comment installer la base de données MySQL 8.0 sous Windows? (tutoriel graphique)
- 案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
- 515. find the maximum value in each tree row
- 两个文件 合并为第三个文件 。
- 【贝叶斯分类4】贝叶斯网
- Daily basic use of alicloud personal image warehouse
- 0基础学c语言(3)
猜你喜欢

Arduino UNO + DS1302利用31字节静态RAM存储数据并串口打印
![[Bayesian classification 2] naive Bayesian classifier](/img/44/dbff297e536508a7c18b76b21db90a.png)
[Bayesian classification 2] naive Bayesian classifier

C language 99 multiplication table

Some cold knowledge about QT database development

GameFi 活跃用户、交易量、融资额、新项目持续性下滑,Axie、StepN 能摆脱死亡螺旋吗?链游路在何方?

好物推荐:移动端开发安全工具

Looking back at the moon

基于QT开发的线性代数初学者的矩阵计算器设计

Tiktok practice ~ homepage video ~ pull-down refresh

飞天+CIPU体为元宇宙带来更大想象空间
随机推荐
这些地区考研太疯狂!哪个地区报考人数最多?
【连载】说透运维监控系统01-监控系统概述
Super VRT
慕课8、服务容错-Sentinel
Dynamic parameter association using postman
leetcode刷题:哈希表08 (四数之和)
Keep alive cache component in Vue
[serial] shuotou O & M monitoring system 01 overview of monitoring system
【最详细】最新最全Redis面试大全(70道)
Development of NFT for digital collection platform
710. random numbers in the blacklist
论数据库的传统与未来之争之溯源溯本----AWS系列专栏
c语言99乘法表
分布式ID生成系统
两个文件 合并为第三个文件 。
Détails de l'annotation des ressources sentinelles
Introduction to single chip microcomputer one-on-one learning strategy, independent development program immediately after reading
Looking back at the moon
710. 黑名单中的随机数
Arduino UNO + DS1302利用31字节静态RAM存储数据并串口打印