Write a function that takes a string as input and returns the string reversed.
Example 1:
Input: "hello"
Output: "olleh"
Example 2:
Input: "A man, a plan, a canal: Panama"
Output: "amanaP :lanac a ,nalp a ,nam A"
思路:差不多应该去做做medium了
class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
return s[::-1]
可以复杂点。(为了学习join()和reversed()方法)
return ''.join(reversed(s))

本文介绍了一个简单的Python函数,该函数接收一个字符串作为输入,并返回其反转后的字符串。通过使用Python内置的切片操作符和reversed()函数,展示了两种实现字符串反转的方法。
707

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



