557. Reverse Words in a String III

Posted 业精于勤荒于嬉,行成于思毁于随

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了557. Reverse Words in a String III相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    string reverseWords(string s) {
        string temp;
		string ret;
		for (int i = 0; i < s.length(); i++) {
			if (s.at(i) == ‘ ‘)
			{
				reverse(temp.begin(), temp.end());
				ret += temp + " ";
				temp.clear();
				continue;
			}
			temp += s.at(i);
		}
		if (s.length() > 0)
		{   
		    reverse(temp.begin(), temp.end());
			ret += temp;
		}
		return ret;
    }
};

  

以上是关于557. Reverse Words in a String III的主要内容,如果未能解决你的问题,请参考以下文章

557. Reverse Words in a String III

557. Reverse Words in a String III

557. Reverse Words in a String III

557. Reverse Words in a String III

557. Reverse Words in a String III

557. Reverse Words in a String III