Skip to main content

Reverse String

描述​

Write a function to reverse a string. The input string is given as an array of characters.

You must do this by modifying the input array in-place with O(1) extra memory.

分析​

无。

代码​

def reverse_string(s):
left, right = 0, len(s) - 1
while left < right:
s[left], s[right] = s[right], s[left]
left += 1
right -= 1

相关题目​