Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
就是return一个反过来的string。
class Solution(object):
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-1]
这个没什么可以说的,熟悉切片操作就好。
本文介绍了一个简单的Python函数,该函数接收一个字符串作为输入并返回其反转后的字符串。例如,输入为'hello'时,输出为'olleh'。文章中提供了一个简洁的实现方式,利用Python的切片操作来完成字符串的反转。
241

被折叠的 条评论
为什么被折叠?



