当前位置:网站首页>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
边栏推荐
- vscode中文插件不生效问题解决
- 8.3 语言模型与数据集
- 8.2 文本预处理
- First acquaintance with STL
- 51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
- A good tool: aardio
- 51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
- 51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- 【NLP】HMM隐马尔可夫+维特比分词
猜你喜欢
电容
Is asemi ultrafast recovery diode interchangeable with Schottky diode
PCIe X1 插槽的主要用途是什么?
The art of automation
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
eolink 如何助力遠程辦公
MySQL报错packet out of order
外包干了四年,废了...
QT Detailed explanation of pro file
What is the main purpose of PCIe X1 slot?
随机推荐
【JZ46 把数字翻译成字符串】
QT interface optimization: QT border removal and form rounding
Alexnet model
Branch statement of process control
DVWA之暴力破解(Brute Force)Low-->high
外包干了四年,废了...
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
2-Go变量操作
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
epoll 的 ET,LT工作模式———实例程序
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
Achievements in science and Technology (21)
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
科技的成就(二十一)
Swift protocol Association object resource name management multithreading GCD delay once
Progress in the treatment of depression
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
中富金石财富班29800效果如何?与专业投资者同行让投资更简单