请编写一个函数,其功能是将输入的字符串反转过来。
示例:
输入:s = "hello" 返回:"olleh"第一种方法
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
s_list=list(s)#转为列表
s_list[:]=s_list[::-1]
s=''.join(s_list)
return s
第二种方法,字符串直接反转
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-1]
