leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0151.cpp (464B)
0 class Solution { 1 public: 2 string reverseWords(string s) { 3 string res = ""; 4 string buff = ""; 5 for (int i = 0; i < s.size(); i++) { 6 if (s[i] != ' ') { 7 buff += s[i]; 8 } else if (buff != "") { 9 res = buff + " " + res; 10 buff = ""; 11 } 12 } 13 if (buff != "") res = buff + " " + res; 14 if (res != "") res.pop_back(); 15 return res; 16 } 17 };