How to make it right?


  • 0
    T

    class Solution {
    public:
    void reverseWords(string &s) {
    reverse(s.begin(),s.end());
    int before=0;
    for(int i=0;i<s.size();i++){
    if(s[i]==' '){

                while(s[i+1]==' '){
                    s.erase(s.begin()+i+1);
                }
                reverse(s.begin()+before,s.begin()+i);
                before=i+1;
            }
        }
        reverse(s.begin()+before,s.end());        
    }
    

    };


Log in to reply
 

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