当前位置:网站首页>leetcode剑指offer jz5 替换空格字符串
leetcode剑指offer jz5 替换空格字符串
2022-07-24 05:22:00 【喜乐自在】

由题意可知,简单的遍历字符串即可
#include<iostream>
using namespace std;
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return string字符串
*/
string replaceSpace(string s) {
// write code here
for(int i=0;i<s.size();i++){
if(s[i]==' '){
s[i]='%';
s.insert(i+1,"20"); //string类中的insert方法insert(字符串的顺序,char类型字符串) 例如s1.insert(6,str2),就是往s1字符串的第6尾后插入str2字符串
}
}
return s;
}
};
边栏推荐
- [principles of database system] Chapter 5 algebra and logic query language: package, extension operator, relational logic, relational algebra and datalog
- Hololens 2 development 101: create the first hololens 2 Application
- JDBC advanced -- learning from Shang Silicon Valley (DAO)
- IP课笔记(4)
- Hololens 2 development: development environment deployment
- Day3 jvm+ sorting summary
- 什么是单调队列
- Openpose unity plug-in deployment tutorial
- Statistical analysis of catering data --- Teddy cloud course homework
- 常见AR以及MR头戴显示设备整理
猜你喜欢

JDBC advanced -- learning from Shang Silicon Valley (DAO)

异地远程连接在家里的群晖NAS【无公网IP,免费内网穿透】

Hit the wall record (continuously updated)

UE4:浅谈什么是GamePlay框架

Hololens 2 Chinese development document MRTK V2

常见十大漏洞总结(原理、危害、防御)

ue4 物品随机生成

MySQL download and installation environment settings

HoloLens 2 开发101:创建首个HoloLens 2应用程序

如何建立一个仪式感点满的网站,并发布到公网 2-2
随机推荐
UE4:浅谈什么是GamePlay框架
Hololens2 development: use MRTK and simulate eye tracking
如何建立一个仪式感点满的网站,并发布到公网 1-2
day1-jvm+leetcode
data normalization
Dameng database_ Supported table types, usage, characteristics
unity2D横版游戏跳跃实时响应
day6-jvm
Yolov5 learning summary (continuously updated)
本地搭建WordPress个人博客,并内网穿透发布上线 (22)
利用内网穿透,实现公网访问内网
Dameng database_ Common user management commands
Unity (III) three dimensional mathematics and coordinate system
将内网映射到公网【无需公网IP】
EXCEL 生成mysql语句批量操作
IP笔记(10)
配置固定的远程桌面地址【内网穿透、无需公网IP】
Accurate calculation of time delay detailed explanation of VxWorks timestamp
JUC concurrent programming foundation (9) -- thread pool
MySQL download and installation environment settings