美文网首页
[LeetCode][Python]344. Reverse S

[LeetCode][Python]344. Reverse S

作者: bluescorpio | 来源:发表于2017-05-09 22:20 被阅读22次

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

    Example:

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

    思路:

    使用Python解决这个问题就极为方便了:s[::-1]

    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    class Solution(object):
        def reverseString(self, s):
            """
            :type s: str
            :rtype: str
            """
            return s[::-1]
    
    
    if __name__ == '__main__':
        sol = Solution()
        s = "hello"
        print sol.reverseString(s)
    

    相关文章

      网友评论

          本文标题:[LeetCode][Python]344. Reverse S

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