【LeetCode】#344 Reverse String

原文链接: http://www.cnblogs.com/surfzjy/p/6212576.html

【Question】

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

  • Example:

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


【My Solution】

  • Slice 切片
class Solution(object):
    def reverseString(self, s):
        """
        :type s: str
        :rtype: str
        """
        s = s[::-1]
        return s
    
  • 分析
    利用python的切片特性,反向切片即可

转载于:https://www.cnblogs.com/surfzjy/p/6212576.html

猜你喜欢

转载自blog.csdn.net/weixin_30500473/article/details/94790858