描述
写一个方法,接受给定字符串作为输入,返回将这个字符串逐个字符翻转后的新字符串。
样例 1:
输入:"hello"
输出:"olleh"
样例 2:
输入:"hello world"
输出:"dlrow olleh"
class Solution:
"""
@param s: a string
@return: return a string
"""
def reverseString(self, s):
# write your code here
l = len(s)
ans = ''
for i in range(l-1,-1,-1):
ans += s[i]
return ans