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 len=s.size();
for(int i=0;i<len/2;++i){
char temp;
temp=s[i];
s[i]=s[len-1-i];
s[len-1-i]=temp;
}
return s;
}
};
class Solution {
public:
string reverseString(string s) {
int i = 0, j = s.size() - 1;
while(i < j){
swap(s[i++], s[j--]);
}
return s;
}
};