当前位置:网站首页>Leetcode sword finger offer jz73 flip word sequence
Leetcode sword finger offer jz73 flip word sequence
2022-07-24 06:24:00 【Happy and at ease】

This question is mainly about string Class object string understanding and use :
The code comments are as follows
#include<iostream>
using namespace std;
class Solution {
public:
string ReverseSentence(string str) {
if (str.empty()) return str; // In special cases, it directly returns a null value
string ret = ""; // Set two empty strings
string tmp = "";
for (int i = str.size()- 1; i >= 0; i--) { // Because the string is inverted , Therefore, traverse forward from the tail
// Merge a word
if (str[i] != ' ') {
tmp = str[i]+tmp; // Note the order in which strings are added New characters should be in tmp Before character
}
// Find a word , Merge words into the result string
else if (str[i] == ' ' ) {
ret = ret+tmp + " "; // ditto New words should be in Before the original word , The order cannot be changed
tmp = "";
}
}
return ret+tmp; // Once you jump out of the loop, the length of the returned string is In both cases, the sum of strings . And note that the order cannot be changed New words should be in front of the string
}
边栏推荐
- Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
- [test tool]
- Dameng database_ Logical architecture foundation
- leetcode剑指offer JZ23:链表中环的入口节点
- Set up a WordPress personal blog locally and launch it through the intranet (22)
- Openpose2d transform 3D pose recognition
- Summary of ten common vulnerabilities (principle, harm, defense)
- Flink production environment configuration recommendations
- Understanding of Flink parallelism
- 如何建立一个仪式感点满的网站,并发布到公网 2-2
猜你喜欢

记一次高校学生账户密码的获取,从无到有

IP笔记(10)
![Map the intranet to the public network [no public IP required]](/img/d0/b391bcfcaeb4c7ad439e241334361b.png)
Map the intranet to the public network [no public IP required]

MySQL从基础到入门到高可用

Unity2d game let characters move - next

IA课总结(1)

Flink production environment configuration recommendations

Simple but easy to use: using keras 2 to realize multi-dimensional time series prediction based on LSTM

How does the latest version of text (TMP) UI text of unity display in Chinese

Hololens 2 Chinese development document MRTK V2
随机推荐
leetcode剑指offer jz5 替换空格字符串
IP notes (11)
IP课笔记(5)
Dameng database_ Logical backup
IP笔记(8)
Configure a fixed remote desktop address [intranet penetration, no need for public IP]
IA笔记 1
Set up a WordPress personal blog locally and launch it through the intranet (22)
Remember 20 classic interview questions of performance test in three minutes
A batch of interview questions and answers_ 20180403 latest arrangement
leetcode剑指offer JZ42 连续子数组的最大和
Summary of ten common vulnerabilities (principle, harm, defense)
Heap overflow of kernel PWN basic tutorial
Li Kou 986. Intersection of interval lists
NTP error: no server suitable for synchronization found
Hololens 2 development 101: create the first hololens 2 Application
Hololens 2 development: development environment deployment
Interview questions for Test Manager / test team leader / Test Supervisor
IP笔记(7)
MySQL从基础到入门到高可用