Skip to content

Commit fbc5314

Browse files
Add type hints to Node and Trie constructors; specify list type in autocomplete method
1 parent 78b855c commit fbc5314

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

data_structures/trie/trie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Node:
3535
- is_end_of_word: Boolean flag indicating if this node marks the end of a valid word
3636
"""
3737

38-
def __init__(self):
38+
def __init__(self) -> None:
3939
self.children: dict[str, Node] = {} # Maps character to child Node
4040
self.is_end_of_word = False # True if node represents end of a valid word
4141

@@ -54,7 +54,7 @@ class Trie:
5454
True
5555
"""
5656

57-
def __init__(self):
57+
def __init__(self) -> None:
5858
"""Initialize Trie with an empty root node.
5959
6060
The root node doesn't represent any character and serves as the entry point.
@@ -389,7 +389,7 @@ def autocomplete(self, prefix: str, limit: int) -> list:
389389
>>> trie.autocomplete("xyz", 5)
390390
[]
391391
"""
392-
results = []
392+
results: list[str] = []
393393
current_node = self.root
394394

395395
# Traverse to the end of the prefix

0 commit comments

Comments
 (0)