当前位置:网站首页>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;
}
};
边栏推荐
- MySQL基础---约束
- Detailed explanation of KMP code distribution
- Unity(三)三维数学和坐标系统
- Dameng database_ Supported table types, usage, characteristics
- 记一次高校学生账户密码的获取,从无到有
- Search of two-dimensional array of "sword finger offer" C language version
- Jestson installs IBus input method
- Find the ArrayList < double > with the most occurrences in ArrayList < ArrayList < double >
- Hololens 2 Chinese development document MRTK V2
- Openpose unity plug-in deployment tutorial
猜你喜欢

IA笔记 1

Unity (III) three dimensional mathematics and coordinate system

Openpose Unity 插件部署教程

Positional argument after keyword argument

UE4: what is the gameplay framework

如何建立一个仪式感点满的网站,并发布到公网 2-2

Unity Shader :实现漫反射与高光反射

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

Jupyter notebook select CONDA environment

Dameng database_ Various methods of connecting databases and executing SQL and scripts under disql
随机推荐
【无需公网IP】为远程桌面树莓派配置固定的公网TCP端口地址
Accessing a one-dimensional array with a pointer
Unity (II) more APIs and physical engines
公网访问内网IIS网站服务器【无需公网IP】
IA笔记 1
Unity2d game let characters move - next
ue4换装系统 1.换装系统的基本原理
Hololens 2 development 101: create the first hololens 2 Application
UE4:浅谈什么是GamePlay框架
Detailed explanation of KMP code distribution
Unity(三)三维数学和坐标系统
Using keras and LSTM to realize time series prediction of long-term trend memory -lstnet
Dameng database_ Common initialization parameters
Foundation of JUC concurrent programming (8) -- read write lock
Dameng database_ Logical backup
Traditional K-means implementation
公网使用Microsoft Remote Desktop远程桌面,随时远程办公
day5-jvm
data normalization
Dameng database_ Dmfldr tool instructions