当前位置:网站首页>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
边栏推荐
- L'externalisation a duré quatre ans.
- Explanation and example application of the principle of logistic regression in machine learning
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- Is asemi ultrafast recovery diode interchangeable with Schottky diode
- GIS数据处理-cesium中模型位置设置
- Swift protocol Association object resource name management multithreading GCD delay once
- Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
- Unity_代码方式添加绑定按钮点击事件
- 三、梯度下降求解最小θ
- ASEMI三相整流桥和单相整流桥的详细对比
猜你喜欢
![[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection](/img/8c/e72e628a44a36bfc7406a002d00215.png)
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection

OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt

剑指 Offer II 019. 最多删除一个字符得到回文(简单)

Bingbing learning notes: take you step by step to realize the sequence table

ASEMI三相整流桥和单相整流桥的详细对比

Svn detailed use tutorial

机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏

ArrayList collection basic usage

Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring

1n5408-asemi rectifier diode
随机推荐
你還不知道責任鏈模式的使用場景嗎?
冰冰学习笔记:一步一步带你实现顺序表
DVWA之暴力破解(Brute Force)Low-->high
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
帧同步 实现
Introduction to Arduino for esp8266 serial port function
[servlet] detailed explanation of servlet (use + principle)
【工厂模式详解】工厂方法模式
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
ASEMI整流模块MDQ100-16在智能开关电源中的作用
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
On the insecurity of using scanf in VS
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
ArrayList collection basic usage
[jz46 translate numbers into strings]
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
QT actual combat: Yunxi calendar
全连接层的作用是什么?
