344. Reverse String
Easy
Problem:
Input: ["h", "e", "l", "l", "o"]
Output: ["o", "l", "l", "e", "h"]What to learn:
Solutions:
List
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
for i in range(len(s) // 2):
tmp = s[i]
s[i] = s[len(s) - i - 1]
s[len(s) - i - 1] = tmpTwo Pointers
Pythonic way
1. reverse() function
2. slicing
Last updated