Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
解题思路:很简单的逆转题
class Solution {
public:
void my_swap(char *s, char *t)
{
char temp = *s;
*s = *t;
*t = temp;
}
string reverseString(string s) {
int length = s.size();
int i = 0;
int j = length - 1;
while (i < j)
{
my_swap(&s[i], &s[j]);
i++;
j--;
}
return s;
}
};