Skip to content

Commit f536db8

Browse files
authored
Update Reverse String - Leetcode 344.py
1 parent 99d51dd commit f536db8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Reverse String - Leetcode 344/Reverse String - Leetcode 344.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# Brute Force Solution
2+
class Solution:
3+
def reverseString(self, s: List[str]) -> None:
4+
"""
5+
Do not return anything, modify s in-place instead.
6+
"""
7+
n = len(s)
8+
T = []
9+
for i in range(n-1, -1, -1):
10+
T.append(s[i])
11+
12+
for i in range(n):
13+
s[i] = T[i]
14+
15+
# Time: O(n)
16+
# Space: O(n)
17+
18+
# Two Pointers (Optimal) Solution
119
class Solution:
220
def reverseString(self, s: List[str]) -> None:
321
"""

0 commit comments

Comments
 (0)