Reverse String C++ Solution

  • 0
    class Solution {
        string reverseString(string s) 
            int n = s.length();    
            for(int i = 0; i < n/2; i++)
                swap(s[i], s[n - i - 1]);
            return s;

    We use half the size of the string to reduce the runtime.

Log in to reply

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