当前位置:网站首页>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
}
边栏推荐
- UE4: what is the gameplay framework
- Dameng database_ Logical backup
- 三分钟记住20道性能测试经典面试题
- Use intranet penetration to realize public network access to the Intranet
- Sorting of common AR and MR head mounted display devices
- 快速简单搭建FTP服务器,并内网穿透实现公网访问【无需公网IP】
- Remember to get the password of college student account once, from scratch
- ue4换装系统 1.换装系统的基本原理
- 10大漏洞评估和渗透测试工具
- 【226】wireshark的参数使用说明
猜你喜欢
随机推荐
Leetcode剑指offer JZ9 双栈实现队列
公网访问内网IIS网站服务器【无需公网IP】
IP lesson summary (3)
IP job (6)
【218】CS架构和BS架构以及数据放在服务端和客户端的利与弊?
微信TBS在线安装内核失败的解决方法
10大漏洞评估和渗透测试工具
IP笔记(9)
Lua Foundation
【226】wireshark的参数使用说明
将内网映射到公网【无需公网IP】
【222】内存溢出及定位
力扣986.区间列表的交集
进程和计划任务管理
Unity2d horizontal game jump real-time response
Remember 20 classic interview questions of performance test in three minutes
Openpose unity plug-in deployment tutorial
ip作业(1)
IP notes (12)
记一次高校学生账户密码的获取,从无到有









