码迷,mamicode.com
首页 > 编程语言 > 详细

Python [Leetcode 344]Reverse String

时间:2016-07-14 03:06:28      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

题目描述:

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)

 

Python [Leetcode 344]Reverse String

标签:

原文地址:http://www.cnblogs.com/zihaowang/p/5668779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!