leetcode 翻转字符串
https://leetcode-cn.com/problems/reverse-words-in-a-string/
TLE代码:
class Solution {
public:
string reverseWords(string s) {
stringstream ss(s);
string buf;
vector<string> ans;
while(ss<<buf){
ans.push_back(buf);
}
for(vector<string>::iterator it = ans.end()-;it==ans.begin();it++){
cout<< *it<<" ";
}
return ;
}
};
亲测用stringstream确实挺慢的.
可以先用reverse 逆序,再挨个单词逆序回来.
leetcode 翻转字符串的更多相关文章
- LeetCode 翻转字符串里的单词
给定一个字符串,逐个翻转字符串中的每个单词. 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 2: 输 ...
- [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [LeetCode] Reverse Words in a String III 翻转字符串中的单词之三
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- [LeetCode] Reverse String II 翻转字符串之二
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- C#版(击败100.00%的提交) - Leetcode 151. 翻转字符串里的单词 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- [LeetCode] 186. Reverse Words in a String II 翻转字符串中的单词 II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [LeetCode] 557. Reverse Words in a String III 翻转字符串中的单词 III
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
随机推荐
- Halcon斑点分析涉及算子及其高阶运用
涉及算子 获取图像 使用ROI 对齐ROI或图像 校正图像 基础内容这里不再重述 预处理图像(过滤) 基础: mean_image(平均平滑过滤),gauss_filter(高斯滤波),binomia ...
- Html5标签——Html5新增标签的含义和使用
HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...
- 01-springboot整合elasticsearch初识
1.elasticsearch 1.es简介 Elasticsearch 是一个分布式.高扩展.高实时的搜索与数据分析引擎.它能很方便的使大量数据具有搜索.分析和探索的能力.充分利用Elas ...
- 总结《深入理解JVM》 G1 篇
注:一下内容主要结合<深入理解JVM>3th总结而来. 接上一篇,我们来说说G1,G1作为现在的主要的JVM GC,被作为各大互联网主要使用的垃圾回收器,了解G1回回收原理和回收过程,才能 ...
- 使用LLDB和debugserver对ios程序进行调试
在没有WIFI的情况下,使用USB连接IOS设备,使用辅助插件usbmuxd来辅助调试.我其实也想用wifi调试,奈何公司的wifi绑定了mac地址,而我又使用的是黑苹果虚拟机,使用桥接的方式修改网段 ...
- 权益质押(Staking):这是关于什么的?
我们最近发表了三篇讲述Fetch.AI分类帐本的文章.这些概述: 我们的权益质押计划的主要特点和验证器的作用 影响我们设计权益质押模型设计的因素 我们的创新共识协议将如何改变用户体验 这些文章包含大量 ...
- 006.Nginx访问控制
一 Nginx连接限制 1.1 HTTP协议的连接与请求 HTTP是建立在TCP, 一次HTTP请求需要先建立TCP三次握手(称为TCP连接),在连接的基础上再进行HTTP请求. HTTP请求建立在一 ...
- Linux 下载工具推荐: Motrix && qbittorrent
Linux下载介绍 Linux下其实下载工具还是蛮多的, 命令行的wget,curl,aria2,甚至于apt 但是个人日常使用下还是有图形化界面比较方便易用.大多数教程里推荐的Uget,可能是我也不 ...
- 解决IOS端微信浏览器input,textarea有内上边框阴影
box-shadow:0px 0px 0px rgba(0,0,0,0); -webkit-appearance:none;
- CentOS7安装Oracle 11g
准备工作 1.下载Oracle安装包:linux.x64_11gR2_database_1of2.zip 和 linux.x64_11gR2_database_2of2.zip ,可以下载到本地,通过 ...