Problem : https://leetcode.com/problems/reverse-string/
An uncommon 2 pointers approach.
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
N = len(s)
for i in range(N//2):
j = N - i - 1
s[i], s[j] = s[j], s[i]
No comments:
Post a Comment