leetcode6 Reverse Words in a String 单词取反
Reverse Words in a String 单词取反
whowhoha@outlook.com
Question:
Given an input string s, reverse the string word by word.
For example, given s = "the sky is blue", return "blue is sky the".
void reverseWords(string &s) {
vector <string>des;
if(s.empty())
return;
int len = s.size();
for(int i = 0; i < len; i++){
if(s[i] == ' ')
continue;
string word;
while(i < len && s[i] != ' '){
word += s[i];
i++;
}
des.push_back(word);
}
reverse(des.begin(), des.end());
if(des.empty())
s = "";
else {
s.clear();
int j ;
for(j = 0; j < des.size() -1; j++){
s += des[j];
s += ' ';
}
s += des[j];
}
}
leetcode6 Reverse Words in a String 单词取反的更多相关文章
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [Swift]LeetCode186. 翻转字符串中的单词 II $ Reverse Words in a String II
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...
- [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#557. Reverse Words in a String III(反转字符串中的单词 III)
题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...
- 【LeetCode】Reverse Words in a String 反转字符串中的单词
一年没有管理博客园了,说来实在惭愧.. 最近开始刷LeetCode,之前没刷过,说来也实在惭愧... 刚开始按 AC Rates 从简单到难刷,觉得略无聊,就决定按 Add Date 刷,以后也可能看 ...
- [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 ...
随机推荐
- React-Native错误笔记-EPERM
运行react-native run-android时出现错误 EPERM:operation not permitted,lstat .............. 解决办法:用Android Stu ...
- Agile.Net 组件式开发平台 - 内核管理组件
敏捷开发体系 软件构件技术:所谓软件构件化,就是要让软件开发像机械制造工业一样,可以用各种标准和非标准的零件来进行组装.软件的构件化和集成技术的目标是:软件系统可以由不同厂商提供的,用不同语言开发 ...
- ios 微信细节
1.登录后,下次登录保存其用户名. * 官方的登录实现 * 1.把用户名和密码放在沙盒 NSString *user = self.userField.text; NSStri ...
- js(jQuery)获取时间搜集
获取JavaScript 的时间使用内置的Date函数完成 var mydate = new Date(); mydate.getYear(); //获取当前年份(2位) mydate.getFull ...
- JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记1
技术很多,例子很多,只好慢慢学,慢慢实践!!现在学的这本书是[JavaScript实战----JavaScript.jQuery.HTML5.Node.js实例大全] 第 3 章 用 JavaScri ...
- 免费的HTML5连载来了《HTML5网页开发实例详解》连载(六)媒体查询
响应式设计的另一个重要技术手段是媒体查询.如果只是简单的设计一个流式布局系统,那么可以保证每个网格按比例的放大和缩小,但有可能会使得在小屏幕下(如手机设备)网格太小而严重影响阅读,这样的设计称不上响应 ...
- 关于IE8以上 不引人css 症状
不知道各位有没有体验过 这样的状况 在同一个文件夹中 <!DOCTYPE html> <html> <head> <meta charset="u ...
- 第一个MapReduce程序
计算文件中每个单词的频数 wordcount 程序调用 wordmap 和 wordreduce 程序. import org.apache.hadoop.conf.Configuration; im ...
- extends 与 implements 的区别
extends与implements是Java继承中使用的两个关键字,但extends与implements使用的情景不同: 1.接口继承接口,使用extends 2.类继承类时,用extends 3 ...
- iOS 简单总结:description方法\NSLog函数
1.description方法是NSObject自带的方法,包括类方法和对象方法 + (NSString *)description; // 默认返回 类名 - (NSString *)descrip ...