[C++] Without.size() or .length()


  • 0
    S
    class Solution {
    public:
        string reverseWords(string s) {
           
           int head=0;
           int tail=0;
           
           if(s.empty())
                return s;
                
          while(s[tail]!=NULL){
              if(s[tail]==' '){
                reverse(s.begin()+head,s.begin()+tail);    
                head=tail+1;
                tail++;
              }
              else if(s[tail+1]==NULL){
                reverse(s.begin()+head,s.begin()+tail+1);
                break;
              }
              else{
                tail++;
              }
          }
         // reverse(s.begin()+head,s.begin()+tail);
          return s;
        }
    
    };
    

Log in to reply
 

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