Skip to content

Commit 80c9fc2

Browse files
committed
Add time/space complexity to docstring in string.py
1 parent 7666fd1 commit 80c9fc2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/basic/string.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def reverse_string(text: str) -> str:
1313
Returns:
1414
str: The reversed string
1515
16+
Time Complexity:
17+
O(n) where n is the length of the string
18+
19+
Space Complexity:
20+
O(n) as a new reversed string is created
21+
1622
Examples:
1723
>>> reverse_string("hello")
1824
'olleh'
@@ -35,6 +41,12 @@ def reverse_string_builtin(text: str) -> str:
3541
Returns:
3642
str: The reversed string
3743
44+
Time Complexity:
45+
O(n) where n is the length of the string
46+
47+
Space Complexity:
48+
O(n) as a new reversed string is created
49+
3850
Examples:
3951
>>> reverse_string_builtin("hello")
4052
'olleh'
@@ -56,6 +68,12 @@ def extract_alphanumeric(s: str) -> str:
5668
Returns:
5769
str: String containing only alphanumeric characters
5870
71+
Time Complexity:
72+
O(n) where n is the length of the string, as we check each character
73+
74+
Space Complexity:
75+
O(n) in the worst case (if all characters are alphanumeric and ASCII)
76+
5977
Examples:
6078
>>> extract_alphanumeric("Hello, World! 123")
6179
'HelloWorld123'

0 commit comments

Comments
 (0)