c++ two pointers (O(n))


  • 0
    string reverseString(string s) {
        int l = 0, r = s.size() - 1;
        while (l < r) swap(s[l++], s[r--]);
        return s;
    }
    

Log in to reply
 

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