首页 > 其他 > 详细

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

时间:2019-01-05 16:29:27      阅读:150      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:https://www.cnblogs.com/wikiwen/p/10224798.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!