当前位置:网站首页>LeetCode151-颠倒字符串中的单词-字符串-模拟
LeetCode151-颠倒字符串中的单词-字符串-模拟
2022-04-23 14:48:00 【李烦烦搞快点】
Note:
先翻转一下子,然后把每个单词抠出来,在翻转一下放到答案里面
好像也可以不开新的string 直接在原来的上面操作
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;
}
};
版权声明
本文为[李烦烦搞快点]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_Ghost812/article/details/124350534
边栏推荐
- 三、梯度下降求解最小θ
- ASEMI超快恢复二极管与肖特基二极管可以互换吗
- 机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
- Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
- Swift - literal, literal protocol, conversion between basic data types and dictionary / array
- 51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
- Progress in the treatment of depression
- Resolve the conflict between computed attribute and input blur event
- 【无标题】
- I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
猜你喜欢

Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring

Don't you know the usage scenario of the responsibility chain model?

capacitance

MySQL error packet out of order

博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA

1N5408-ASEMI整流二极管1N5408

成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍

3、 Gradient descent solution θ

QT actual combat: Yunxi calendar

Role of asemi rectifier module mdq100-16 in intelligent switching power supply
随机推荐
Introduction to Arduino for esp8266 serial port function
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Mds55-16-asemi rectifier module mds55-16
ASEMI三相整流桥和单相整流桥的详细对比
三、梯度下降求解最小θ
8.4 循环神经网络从零实现
UML project example -- UML diagram description of tiktok
The art of automation
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Svn detailed use tutorial
Go basic reflection
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
Explanation and example application of the principle of logistic regression in machine learning
外包干了四年,废了...
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
DVWA之暴力破解(Brute Force)Low-->high
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
Arduino for esp8266串口功能简介
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
