[LeetCode]Reverse Words in a String
2014-05-11 10:19
375 查看
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
For example,
Given s = "the sky is blue",
return "blue is sky the".
class Solution { public: void reverseWords(string &s) { std::stringstream ss(s); std::string word; std::vector< std::string> temp; while (ss>>word) { temp.push_back(word); temp.push_back(" "); } s = ""; for (int i = temp.size() - 2; i >= 0; i--) { s += temp[i]; } } };
相关文章推荐
- Leetcode 151. Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- Leetcode Reverse Words in a String
- leetcode_Reverse Words in a String
- leetcode-java-151. Reverse Words in a String
- leetcode-Reverse Words in a String
- *LeetCode-Reverse Words in a String II
- [LeetCode] Reverse Words in a String II
- LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation
- Leetcode Reverse Words in a String
- leetcode JAVA Reverse Words in a String 难度系数2-3?最新题151
- [Leetcode][JAVA] Reverse Words in a String
- LeetCode Reverse Words in a String(反转字符串)
- Leetcode: Reverse Words in a String
- python:leetcode之reverse words in a string
- 【leetcode】Reverse Words in a String
- 20170225-leetcode-151-Reverse Words in a String
- LeetCode:Reverse words in a String
- LeetCode:Reverse Words in a String
- LeetCode——Reverse Words in a String