Help me to correct my code for reverse string


  • 0
    D

    I am getting Output limit exceede..

    #include<sstream>

    class Solution {
    public:
    void reverseWords(string &s) {
    string word;
    vector<string> st;

    istringstream iss(s);
    
    while(iss>>word)
    {
        st.push_back(word);
    }
    
    int n;
    n=st.size();
    
    if(n==0)
    {cout<<"";}
    else{
        int i=n-1;
        while(i>0)
        {
        cout<<st[i]<<" ";
        i--;
        }
       cout<<st[i];
    }
        
    }
    

    };


  • 0
    S

    cout makes it happen. Check out OJ FAQ.

    However, question about code you've written must describe the specific problem clearly, elaborate thoughts based on code. Please read the Discuss FAQ for more info.


Log in to reply
 

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