请编写一个函数,其功能是将输入的字符串反转过来。
方案一:切片方式反转
class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[: : -1]
方案二:用list的reverse()反转
class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
l = list(s)
l.reverse()
return ''.join(l)