A Simple O(1) Space C++ Solution


  • 0
    Y
    class Solution {
    public:
        string reverseString(string s) {
            char temp;
            for(int i = 0; i < s.length()/2; i++) {
                temp = s[i];
                s[i] = s[s.length() - 1 - i];
                s[s.length() - 1 - i] = temp;
            }
            return s;
        }
    };

Log in to reply
 

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