File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ def reverse_string(text: str) -> str:
13
13
Returns:
14
14
str: The reversed string
15
15
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
+
16
22
Examples:
17
23
>>> reverse_string("hello")
18
24
'olleh'
@@ -35,6 +41,12 @@ def reverse_string_builtin(text: str) -> str:
35
41
Returns:
36
42
str: The reversed string
37
43
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
+
38
50
Examples:
39
51
>>> reverse_string_builtin("hello")
40
52
'olleh'
@@ -56,6 +68,12 @@ def extract_alphanumeric(s: str) -> str:
56
68
Returns:
57
69
str: String containing only alphanumeric characters
58
70
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
+
59
77
Examples:
60
78
>>> extract_alphanumeric("Hello, World! 123")
61
79
'HelloWorld123'
You can’t perform that action at this time.
0 commit comments