一、问题描述
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) {
if(s == "") return "";
for(int i = 0, j = s.size() - 1; i < j; i++,j--){
char t = s[i];
s[i] = s[j];
s[j] = t;
}
return s;
}
};