Why my code is Output Limit Exceeded, why?


  • 0
    D
    void reverseWords(string &s) {
         int start,end;
    	 for(int i = s.size()-1; i >= 0; i--)
    	 {
    		 while(i >= 0 && s.at(i) == ' ') i--;
    		 end  = i + 1;
    
    		 while(i >= 0 && s.at(i) != ' ') i--;
    		 start = i + 1;
    
    		 if(start != end)
    			 cout<<s.substr(start,end-start)<<" ";
    	 }

  • 1
    L

    you don't need to print the actual result (which I haven't checked for correctness), you just need to process the string, and since it being passed as a reference, the evaluation code will pick the modified string.


  • 0
    D

    oh I got it! thank you


Log in to reply
 

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