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 翻转字符串的更多相关文章

  1. LeetCode 翻转字符串里的单词

    给定一个字符串,逐个翻转字符串中的每个单词. 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 2: 输 ...

  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 ...

  3. [LeetCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  4. [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 ...

  5. [LeetCode] Reverse String II 翻转字符串之二

    Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...

  6. C#版(击败100.00%的提交) - Leetcode 151. 翻转字符串里的单词 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  7. [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& ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. JavaScript基础JavaScript的常用编码惯例(007)

    采用一定的编码惯例,可以使得项目中的代码提到较高的一致性,可读性和可预测性. 1.缩进缩 进可以提高代码的可读性.不过错误的缩进也可能导致代码的误读.有人认为缩进应该使用tab,另外的一些人主张采用4 ...

  2. 逻辑式编程语言极简实现(使用C#) - 3. 运行原理

    本系列前面的文章: 逻辑式编程语言极简实现(使用C#) - 1. 逻辑式编程语言介绍 逻辑式编程语言极简实现(使用C#) - 2. 一道逻辑题:谁是凶手 第二天,好为人师的老明继续开讲他的私人课堂. ...

  3. 什么是JDK的SPI机制

    什么是SPI和API Application Programming Interface (API)? The API is the description of classes/interfaces ...

  4. 浅谈JVM和垃圾回收

    写在前面 简单的介绍一下JVM(Java Virtual Machine)吧,它也叫Java虚拟机.虽然它叫虚拟机,但是实际上不是我们所理解的虚拟机,它更像操作系统中的一个进程.JVM屏蔽了各个操作系 ...

  5. Web前端开发未来的六大趋势

    说起Web前端开发想必你一定不会陌生,因为现在的前端开发学习的培训机构也是层出不穷.下面济南优就业IT培训给大家总结出了未来Web前端开发的六大趋势从中可以大致看出来Web前端未来的发展前景. 趋势一 ...

  6. JVM学习篇-第一篇

    JVM学习篇-第一篇 JDK( Java Development Kit): ​ Java程序设计语言.Java虚拟机.Java类库三部分统称为JDK,JDK是用于支持Java程序开发的最小环境** ...

  7. Selenium之浏览器驱动下载和配置使用

    浏览器驱动下载 Chrome浏览器驱动:chromedriver , taobao备用地址 Firefox浏览器驱动:geckodriver Edge浏览器驱动:MicrosoftWebDriver ...

  8. Python Java 快速配置环境变量(Path)

    Python Java 快速配置环境变量(Path) 最近系统被重置,清空了C盘中的program等文件夹以及初始化了环境变量. 通常环境下,在windows环境中我们都会打开"环境变量&q ...

  9. CF833 A The Meaningless Game

    题干 Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting ...

  10. Rancher1.6 部署prometheus

    一.rancher基础配置 镜像:prom/prometheus:latest 映射端口:9090:9090 服务连接: blackbox-exporter cadvisor node-exporte ...