【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的切片特性,反向切片即可