您的位置:首页 > 其它

[LeetCode]Reverse Words in a String

2014-04-12 17:46 381 查看
class Solution {
public:
void reverseWords(string &s) {
string word;
stack<string> wordsStack;
stringstream ss(s);
while(ss>>word)
{
wordsStack.push(word);
}
string res = "";
bool first = true;
while(!wordsStack.empty())
{
if(!first)
res += " ";
res += 	wordsStack.top();
wordsStack.pop();
first = false;
}
s = res;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: