class Solution:
def reverseString(self, s):
"""
:type s: str
:rtype: str
"""
L = len(s)
out = ""
for i in range(L):
j = L - 1 - i
out += s[j]
return out
# 使用切片更简单 s[: : -1]
leetcode - 344 - 反转字符串
最新推荐文章于 2023-12-17 11:55:38 发布
本文介绍了一种在Python中反转字符串的方法,通过遍历字符串并从后向前构建新字符串来实现。此外,还提供了一个更简洁的解决方案,利用Python的切片功能直接反转字符串。
1646

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



