344. Reverse String

来源:互联网 发布:Unity3d添加GameObject 编辑:程序博客网 时间:2024/06/10 11:20

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

Example:

Given s = "hello", return "olleh".


</pre><pre name="code" class="cpp">class Solution {public:    string reverseString(string s) {        if(s.empty()){            return s;        }        int l=0, r=s.size()-1;        string str=s;        while(l<r){            char t=str[l];            str[l]=str[r];            str[r]=t;            l++;            r--;        }        return str;            }};



0 0