您的位置:首页 > 编程语言 > Python开发

Python [Leetcode 344]Reverse String

2016-07-14 00:14 555 查看
题目描述:

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

解题思路:

见代码。

代码如下:

class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
t = list(s)
l = len(t)
for i, j in zip(range(l - 1, 0, -1), range(l // 2)):
t[i], t[j] = t[j], t[i]

return ''.join(t)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: