[LeetCode][Python]344. Reverse S

2017-05-09  本文已影响22人  bluescorpio

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)
上一篇 下一篇

猜你喜欢

热点阅读