concise C++


  • 0
    P
    class Solution {
    public:
        void reverseWords(string &s) {
            auto pre = s.begin();
            for(auto x = s.begin(); x <= s.end(); ++x)
            {
                if(*x == ' ' || x == s.end() ) 
                {
                    reverse(pre,x);
                    pre = x + 1;
                }
                
            }
            reverse(s.begin(), s.end());
            return;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.