344. Reverse String
Write a function that takes a string as input and returns the string reversed.
题目大意:反向输出字符串
Example:
Given s = "hello", return "olleh".
代码如下
C++
class Solution {
public:
string reverseString(string s) {
int a = s.size()-1;
string b = "";
for(int i=a;i>=0;i--)
b += s[i];
return b;
}
};
注意:设置a是为了不用每次循环都执行s.size()-1