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

Leetcode 344.反转字符串 By Python

时间:2018-06-19 22:41:38      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:字符   实现   IV   ever   string   ret   字符串反转   leetcode   解决   

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

示例:

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

思路

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

赞美Python!

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

Leetcode 344.反转字符串 By Python

标签:字符   实现   IV   ever   string   ret   字符串反转   leetcode   解决   

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

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