Reverse string

Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh"
    
c++ solution1:
class solution1:
{
    public:
        string reverseString(string s){
            int left = 0,right = s.size() - 1;
            while(left < right){
                char t = s[left];
                s[left++] = s[right];
                s[right--] = t;
            }
            return s;
        }
};  



C++ solution2:
class Solution{
    public:
        string reverseString(string s){
            int left = 0,right = s.size() - 1;
            while(left < right)
            {
                swap(s[left++],s[right--]);
            }
            return s;
        }
};
怕什么真理无穷,进一寸有一寸的欢喜。---胡适
原文地址:https://www.cnblogs.com/hujianglang/p/11520203.html