C++ Solution


  • 9
    S
    class Solution {
    public:
        string reverseWords(string s) {
            size_t front = 0;
            for(int i = 0; i <= s.length(); ++i){
                if(i == s.length() || s[i] == ' '){
                    reverse(&s[front], &s[i]);
                    front = i + 1;
                }
            }
            
            return s;
        }
    };
    

Log in to reply
 

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