当前位置:网站首页>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
}
边栏推荐
- 简单三步快速实现内网穿透
- Li Kou 986. Intersection of interval lists
- How to build a website full of ritual sense and publish it on the public website 2-2
- IP笔记(8)
- Flink production environment configuration recommendations
- List of problems in the re disk guidance of the project
- Simple but easy to use: using keras 2 to realize multi-dimensional time series prediction based on LSTM
- Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
- IP笔记(12)
- leetcode剑指offer jz5 替换空格字符串
猜你喜欢

Top 10 vulnerability assessment and penetration testing tools

First knowledge of graphics
![Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]](/img/2a/43ba2839b842e0901a550d2883b883.png)
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]

IP笔记(12)

Sorting of common AR and MR head mounted display devices

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

MySQL数据库—SQL汇总(记得关注我!中国加油!)

Remember to get the password of college student account once, from scratch

Unity shader: realize diffuse reflection and specular reflection

Do not rent servers, build your own personal business website (2)
随机推荐
不租服务器,自建个人商业网站(3)
Unity2d game let characters move - next
IP笔记(10)
Flink checkpoint configuration details
剑指offer JZ10斐波那契数列
Unity shader migrated from built-in rendering pipeline to URP
UE4: what is the gameplay framework
IP课笔记(4)
【222】内存溢出及定位
测试经理/测试组长/测试主管面试题
Unity (II) more APIs and physical engines
力扣986.区间列表的交集
Unity (III) three dimensional mathematics and coordinate system
不租服务器,自建个人商业网站(如何购买域名)
Ia note 1
Leetcode剑指offer JZ9 双栈实现队列
不租服务器,自建个人商业网站(1)
[214] what is an automation framework
Top 10 vulnerability assessment and penetration testing tools
Use intranet penetration to realize public network access to the Intranet