标签:string ring for span -- rds png 解答 ==
题目:
解答:
1 class Solution { 2 public: 3 string reverseWords(string s) 4 { 5 if (s.empty()) 6 { 7 return s; 8 } 9 10 int len = 0; 11 string ans = ""; 12 13 for (int m = s.size() - 1; m >= 0; m--) 14 { 15 if (s[m] == ‘ ‘ && len != 0) 16 { 17 ans += s.substr(m+1, len) + " "; 18 len = 0; 19 continue; 20 } 21 if (s[m] != ‘ ‘) 22 { 23 len++; 24 } 25 } 26 27 if (len != 0) 28 { 29 ans += s.substr(0, len) + " "; 30 } 31 32 if (ans.size() > 0) 33 { 34 ans.erase(ans.size() - 1, 1); 35 } 36 37 return ans; 38 39 } 40 };
标签:string ring for span -- rds png 解答 ==
原文地址:https://www.cnblogs.com/ocpc/p/12825959.html