题目:
Write a function that takes a string as input and returns the string reversed.
Example 1:
Input: “hello”
Output: “olleh”
Example 2:
Input: “A man, a plan, a canal: Panama”
Output: “amanaP :lanac a ,nalp a ,nam A”
解释:
字符串翻转。
python代码:
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-1]
c++代码:
#include <algorithm>
class Solution {
public:
string reverseString(string s) {
reverse(s.begin(),s.end());
return s;
}
};
总结: