Write a function that takes a string as input and returns the string reversed.
Example: Given s = “hello”, return “olleh”.
思路: 先转换成列表,然后直接通过reverse()函数来实现 关键在于字符串与列表之间的相互转换
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
lstr = []
for c in s:
lstr.append(c)
lstr.reverse()
#print(''.join(lstr))
return ''.join(lstr)
if __name__ == "__main__":
s = "hello"
print(Solution().reverseString(s))