C++ Three Solutions. One Line Code, Two Line Codes and 3 Line Codes!


  • 0
    A
    string reverseString(string s) {
        // return string(s.rbegin(),s.rend());
    
        // reverse(s.begin(),s.end());
        // return s;
    
        for(int i=0;i<s.size()/2;i++){
            swap(s[i],s[s.size()-i-1]);
        }
    
        return s;
    }

Log in to reply
 

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