当前位置:网站首页>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);
}
}

边栏推荐
- 0 basic C language (3)
- [most detailed] the latest and complete redis interview (70)
- [most detailed] latest and complete redis interview (42 tracks)
- Jz-062- the k-th node of binary search tree
- 这些地区考研太疯狂!哪个地区报考人数最多?
- C: Reverse linked list
- Serial port application program based on gd32
- c语言99乘法表
- 710. random numbers in the blacklist
- 460million zongzi were sold in half a year. How big is the "imagination space" of time-honored brands?
猜你喜欢

西瓜书重温(七): 贝叶斯分类器(手推+代码demo)

IDEA 报错:Process terminated【已解决】

Gamefi active users, transaction volume, financing amount and new projects continue to decline. Can axie and stepn get rid of the death spiral? Where is the chain tour?
![[Bayesian classification 3] semi naive Bayesian classifier](/img/9c/070638c1a613be648466e4f2bc341e.png)
[Bayesian classification 3] semi naive Bayesian classifier

【连载】说透运维监控系统01-监控系统概述

Tiktok practice ~ homepage video ~ pull-down refresh

Tiktok practice ~ search page ~ video details

leetcode刷题:字符串04(颠倒字符串中的单词)

Tiktok practice ~ sharing module ~ generate short video QR code

Disruptor local thread queue_ Use transprocessor processor and workpool to compare consumption - Notes on inter thread communication 005
随机推荐
MySQL stored procedure
MongoDB实现创建删除数据库、创建删除表(集合)、数据增删改查
Keep alive cache component in Vue
On the origin of the dispute between the tradition and the future of database -- AWS series column
BOM and DOM operations
开户可以在网上开么?能安全吗?
Six necessary threat tracking tools for threat hunters
c语言99乘法表
IDEA 报错:Process terminated【已解决】
Tiktok practice ~ search page ~ video details
记录一次Redis大Key的排查
0基础学c语言(2)
460million zongzi were sold in half a year. How big is the "imagination space" of time-honored brands?
Tiktok practice ~ sharing module ~ copy short video link
QT两种方法实现定时器
【最详细】最新最全Redis面试大全(42道)
2022/02/14 line generation
Feitian +cipu body brings more imagination to the metauniverse
Unity——Mathf. Similarities and differences between atan and atan2
[serial] shuotou O & M monitoring system 01 overview of monitoring system