【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;
    }
};

 

posted @ 2019-01-05 15:50  wikiwen  阅读(90)  评论(0编辑  收藏  举报