LeetCode 344. Reverse String 题解(C++)
题目描述
- Write a function that takes a string as input and returns the string reversed.
示例
- Given s = “hello”, return “olleh”.
代码
class Solution
{
public:
string reverseString(string s)
{
string str = s;
int length = s.size();
for (int i = length - 1; i >= 0; --i)
{
str[length - 1 - i] = s[i];
}
return str;
}
};