344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
代码:
class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
# out=''
# for i in range(len(s)):
# out+=s[len(s)-i-1]
# return out
return s[::-1]
本文介绍了一个简单的字符串反转函数实现方法,该方法通过Python内置操作高效地完成字符串的反转。
2187

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



