【LeetCode】#344 Reverse String

【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的切片特性,反向切片即可
posted @ 2016-12-22 19:32  涉风  阅读(108)  评论(0编辑  收藏  举报