1、题目描述

2、问题分析

使用一个vector存储每个单词。

3、代码

 void reverseWords(string &s) {
vector<string> v;
for (string::iterator it = s.begin(); it != s.end(); ) {
if (*it == ' ') {
it++;
}
else {
auto itr = it + ; while (*itr != ' ' && itr != s.end()) {
itr++;
} string sub = s.substr(it - s.begin(), itr - it);
v.push_back(sub);
if (itr == s.end())
break;
it = itr + ;
}
} s.clear();
for (vector<string>::reverse_iterator rv = v.rbegin(); rv != v.rend(); rv++) {
if (rv + != v.rend()) {
s += *rv;
s += ' ';
} else {
s += *rv;
}
} }

LeetCode 题解之Reverse Words in a String的更多相关文章

  1. leetcode面试准备:Reverse Words in a String

    leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. ...

  2. 【leetcode】557. Reverse Words in a String III

    Algorithm [leetcode]557. Reverse Words in a String III https://leetcode.com/problems/reverse-words-i ...

  3. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  4. 【LeetCode】151. Reverse Words in a String

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...

  5. 【LeetCode练习题】Reverse Words in a String

    Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...

  6. 【leetcode】345. Reverse Vowels of a String

    problem 345. Reverse Vowels of a String class Solution { public: string reverseVowels(string s) { , ...

  7. 【刷题-LeetCode】151 Reverse Words in a String

    Reverse Words in a String Given an input string, reverse the string word by word. Example 1: Input: ...

  8. 【一天一道LeetCode】#345. Reverse Vowels of a String

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  9. LeetCode算法题-Reverse Words in a String III(Java实现)

    这是悦乐书的第259次更新,第272篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第126题(顺位题号是557).给定一个字符串,您需要反转句子中每个单词中的字符顺序,同 ...

随机推荐

  1. chrome中Timeline的使用(译)

    一.概括 Timeline面板包括以下四个部分: 控制面板.开始记录.停止记录.配置捕获信息: 概况.页面性能的整体概况: flame chart.直观展示cpu堆的情况.你能够看到三条虚线,蓝色的代 ...

  2. JAVA多态计算面积main函数调用方法

    public static void main(String[] args) { Shape shape; Scanner input = new Scanner(System.in); System ...

  3. 使用Codis-Admin命令配置环境

    前提条件:由于22.35.60服务器各自配置了Codis-Service主机,所以22.35.60对应的ip和端口要求能通信和互信访问,为下面通过60的dashboard配置22.35.60实现分组. ...

  4. spring mvc 404页面制作

    1.404页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  5. SpringBoot入门 (十四) Security安全控制

    本文记录在SpringBoot使用SpringSecurity进行安全访问控制. 一 什么是Security Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访 ...

  6. 解决webstorm本地IP访问页面出错的问题

    想在手机端访问webstorm做出的页面,遇到了根据IP地址访问页面错误的问题,试了网上的方法:“设置webstorm可以被外部连接访问”,依旧不能解决 解决方法: 在webstorm下:ctrl+a ...

  7. Vue怎么使用Echarts创建图表

    摘要:在后台管理系统中,我们经常会遇到图表,比如说:柱形图,饼状图,折线图,雷达图等等,而用来写图表插件有很多,我这里主要介绍Echarts在项目里怎么使用,官网地址如下:https://echart ...

  8. myeclipse或eclipse无法从wtpServer添加tomcatServer

    在eclipse想把之前的Tomcat 6删掉,重新配置一个,不料没有下一步 Cannot create a server using the selected type 这句话出现在窗口上面,应该不 ...

  9. Android - Dagger2 使用和原理

    Dagger2从入门到放弃再到恍然大悟 http://www.jianshu.com/p/cd2c1c9f68d4 http://www.jianshu.com/p/39d1df6c877d http ...

  10. Codeforces500C(SummerTrainingDay01-G)

    C. New Year Book Reading time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...