- 描述:Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
- 分析:转换字符串的方向,水题
- 思路一:利用for循环从后向前读取。
class Solution {
public:
string reverseString(string s) {
string res = "";
for (int i = s.size() - 1; i >= 0; i--) {
res += s[i];
}
return res;
}
};