当前位置:网站首页>leetcode刷题:字符串03(剑指 Offer 05. 替换空格)
leetcode刷题:字符串03(剑指 Offer 05. 替换空格)
2022-06-26 20:30:00 【涛涛英语学不进去】
题目:剑指Offer 05.替换空格
请实现一个函数,把字符串 s 中的每个空格替换成"%20"。
示例 1:
输入:s = “We are happy.”
输出:“We%20are%20happy.”
想着蛮简单的,只要知道空格的Ascll码就行了。一发入魂。
没啥好说的。
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/ * 剑指 Offer 05. 替换空格 **/
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);
}
}

边栏推荐
- Distributed ID generation system
- Muke 11. User authentication and authorization of microservices
- 【贝叶斯分类3】半朴素贝叶斯分类器
- Tiktok practice ~ search page ~ video details
- GameFi 活跃用户、交易量、融资额、新项目持续性下滑,Axie、StepN 能摆脱死亡螺旋吗?链游路在何方?
- 郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布
- 抖音实战~搜索页面~视频详情
- 分布式ID生成系统
- 抖音实战~分享模块~复制短视频链接
- C: 反转链表
猜你喜欢

飞天+CIPU体为元宇宙带来更大想象空间

Selection of database paradigm and main code

Unit test of boot

Feitian +cipu body brings more imagination to the metauniverse

Boot indicator monitoring

Guomingyu: Apple's AR / MR head mounted display is the most complicated product in its history and will be released in January 2023

抖音实战~分享模块~短视频下载(保存到相册)

【贝叶斯分类3】半朴素贝叶斯分类器

Boot指标监测

Tiktok practice ~ search page ~ video details
随机推荐
浏览器的垃圾回收机制
Is it safe to open a securities account? Is there any danger
C language file cursor fseek
GEE:计算image区域内像素最大最小值
0基础学c语言(3)
Developer survey: rust/postgresql is the most popular, and PHP salary is low
Can I open an account online? Is it safe?
Kubernetes 资源拓扑感知调度优化
c语言99乘法表
SentinelResource注解詳解
Tiktok practice ~ search page ~ scan QR code
Tiktok practice ~ sharing module ~ short video download (save to photo album)
Disruptor local thread queue_ Use transprocessor processor and workpool to compare consumption - Notes on inter thread communication 005
Selection of database paradigm and main code
动态规划111
【最详细】最新最全Redis面试大全(70道)
[recommended collection] these 8 common missing value filling skills must be mastered
Feitian +cipu body brings more imagination to the metauniverse
孙老师版本JDBC(2022年6月12日21:34:25)
Détails de l'annotation des ressources sentinelles