美文网首页
LeetCode 字符串 反转字符串

LeetCode 字符串 反转字符串

作者: Eddiehe212 | 来源:发表于2018-08-12 15:22 被阅读0次

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

示例 1:
输入: "hello"
输出: "olleh"

示例 2:
输入: "A man, a plan, a canal: Panama"
输出: "amanaP :lanac a ,nalp a ,nam A"

解答:

这道题使用python非常简单,可以直接使用切片来判断。

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

相关文章

网友评论

      本文标题:LeetCode 字符串 反转字符串

      本文链接:https://www.haomeiwen.com/subject/wpmsbftx.html