标签:size 思路 class note between red strong end rds
题目描述:
Example:
Input: "the sky is blue
", Output: "blue is sky the
".
Note:
Follow up: For C programmers, try to solve it in-place in O(1) space.
解题思路:
题目不难,直接代码
代码:
1 class Solution { 2 public: 3 void reverseWords(string &s) { 4 reverse(s.begin(), s.end()); 5 istringstream sin(s); 6 string word, res; 7 while (sin>>word) { 8 reverse(word.begin(), word.end()); 9 res += word; 10 res += " "; 11 } 12 if (res.size() > 0) 13 res.erase(res.size() - 1, 1); 14 s = res; 15 } 16 };
151. Reverse Words in a String
标签:size 思路 class note between red strong end rds
原文地址:https://www.cnblogs.com/gsz-/p/9457126.html