8ms c++ solution


  • 1
    A
    class Solution {
    public:
        void reverseWords(string &s) {
            int start = 0;
            int end;
    
            std::reverse(s.begin(),s.end());        
            for (start = 0;start < s.length();start = end + 1)
            {
                end = s.find(' ',start);
                if (end == std::string::npos) end = s.length();
                std::reverse(s.begin() + start, s.begin() + end);
            }
        }
    };

Log in to reply
 

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