首页 > 编程语言 > 详细

Leetcode 344.反转字符串 By Python

时间:2018-06-19 22:25:26      阅读:170      评论:0      收藏:0      [点我收藏+]

请编写一个函数,其功能是将输入的字符串反转过来。

示例:

输入:s = "hello"
返回:"olleh"

思路

Python里面的切片用来解决这个问题就很快了,仅仅一行就实现了反转字符串!

赞美Python!

class Solution:
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        return s[::-1]

Leetcode 344.反转字符串 By Python

原文:https://www.cnblogs.com/MartinLwx/p/9201138.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!