Difficulty: Easy
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
简单地翻转字符串,因为太懒,不想写个for循环,直接调用reverse函数,时间复杂度O(n).
class Solution {
public:
string reverseString(string s) {
string res = s;
reverse(res.begin(),res.end());
return res;
}
};