Skip to content

Commit 24d1711

Browse files
Update algorithms/stack/reverse_string/__init__.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 8ae26e0 commit 24d1711

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

algorithms/stack/reverse_string/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,22 @@ def reverse_string(text: str) -> str:
3333
return reversed_string
3434

3535

36-
def reverse_string_char_array(s: List[str]):
36+
def reverse_string_char_array(s: List[str]) -> None:
37+
"""
38+
Reverses a character array in place using two-pointer technique.
39+
40+
Reference: https://leetcode.com/problems/reverse-string/
41+
42+
Complexity:
43+
Where n is the length of the input list
44+
Time: O(n), each character is visited at most once
45+
Space: O(1), only two pointers used, no extra data structures
46+
47+
Args:
48+
s (List[str]): character array to reverse in place
49+
Returns:
50+
None: modifies the input list in place
51+
"""
3752
if not s or len(s) == 1:
3853
return
3954

0 commit comments

Comments
 (0)