题目链接:https://leetcode.com/problems/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 left=0, right=s.length()-1;
while(left<right)
{
swap(s[left], s[right]);
left++, right--;
}
return s;
}
};