当前位置:网站首页>Leetcode151 - invert words in string - String - simulation
Leetcode151 - invert words in string - String - simulation
2022-04-23 14:48:00 【Li Fan, hurry up】
Note:
Turn it over first , Then pick out each word , Turn it over and put it in the answer
It seems that you can't open a new one string Operate directly on the original
class Solution {
public:
string reverseWords(string s) {
string ans;
reverse(s.begin(), s.end());
int p = 0;
while(p < s.size()){
string word = "";
while(s[p] == ' ' && p < s.size()) p ++;
while(s[p] != ' ' && p < s.size()) word += s[p ++];
reverse(word.begin(), word.end());
ans += word;
ans += ' ';
}
ans.pop_back();
if(ans[ans.size() - 1] == ' ') ans.pop_back();
return ans;
}
};
版权声明
本文为[Li Fan, hurry up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231447599818.html
边栏推荐
- Want to be an architect? Tamping the foundation is the most important
- 1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
- 【工厂模式详解】工厂方法模式
- SQLSERVER事物与锁的问题
- 成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
- ASEMI整流模块MDQ100-16在智能开关电源中的作用
- 3、 Gradient descent solution θ
- 三、梯度下降求解最小θ
- QT actual combat: Yunxi chat room
- ArrayList collection basic usage
猜你喜欢
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
Svn detailed use tutorial
[jz46 translate numbers into strings]
你還不知道責任鏈模式的使用場景嗎?
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
[detailed explanation of factory mode] factory method mode
eolink 如何助力遠程辦公
8.3 语言模型与数据集
Explanation and example application of the principle of logistic regression in machine learning
随机推荐
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
解决computed属性与input的blur事件冲突问题
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
OpenFaaS实战之四:模板操作(template)
QT actual combat: Yunxi chat room
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
The initial C language framework is suitable for review and preliminary understanding
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
《JVM系列》 第七章 -- 字节码执行引擎
L'externalisation a duré quatre ans.
How do I open the win10 startup folder?
Epolloneshot event of epoll -- instance program
Don't you know the usage scenario of the responsibility chain model?
SVN详细使用教程
vscode中文插件不生效问题解决
电容
1n5408-asemi rectifier diode
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
Role of asemi rectifier module mdq100-16 in intelligent switching power supply