C++ two pointer.


  • 0
    class Solution {
    public:
      string reverseString(string s) {
        int i = 0, j = s.size() - 1;
    
        while (i < j)
        {
          char tmp = s[i];
          s[i] = s[j];
          s[j] = tmp;
          i ++;
          j --;
        }
        return s;
      }
    };
    

Log in to reply
 

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