【LeetCode & 剑指offer刷题】字符串题3:Reverse String

【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...)

Reverse String

 
Write a function that takes a string as input and returns the string reversed.

 

Example:
Given s = "hello", return "olleh".
 
/*class Solution
{
public:
    string reverseString(string s)
    {
        int i = 0;
        int j = s.size() - 1;
        while(i<j)
        {
            swap(s[i++],s[j--]);
        }
       
        return s;
    }
};*/
class Solution
{
public :
    string reverseString ( string s )
    {
        reverse ( s . begin (), s . end ());
        return s ;
    }
};

猜你喜欢

转载自www.cnblogs.com/wikiwen/p/10224798.html