class Solution {
public:
void reverseWords(string &s) {
istringstream input(s);
stack<string> str;
string temp;
while(input>>temp){
str.push(temp);
}
s.clear();
while(!str.empty()){
temp=str.top();
s.insert(s.end(),temp.begin(),temp.end());
str.pop();
if(str.size()){
s.push_back(' ');
}
}
}
};
LeetCode - 151 Reverse Words in a String
最新推荐文章于 2022-07-02 13:47:25 发布