Skip to content

Commit 4e18df4

Browse files
committed
feat: update trie json
1 parent 73afc41 commit 4e18df4

File tree

4 files changed

+15
-79
lines changed

4 files changed

+15
-79
lines changed

.amazonq/rules/problem-creation.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ When creating JSON properties that use PascalCase (solution_class_name, test_cla
136136
- Complex test setup with operation sequences
137137
- Import custom class in test_imports
138138

139+
### Dict-based Tree Problems (Trie, etc.)
140+
141+
- Add `"solution_imports": "from leetcode_py.data_structures import DictTree"`
142+
- Inherit from `DictTree[str]` for string-based trees like Trie
143+
- Provides automatic visualization capabilities
144+
- Use `dict[str, Any]` for internal tree structure
145+
139146
## Generation Commands
140147

141148
```bash

.templates/leetcode/json/implement_trie_prefix_tree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"problem_name": "implement_trie_prefix_tree",
3-
"solution_class_name": "Trie",
3+
"solution_class_name": "Trie(DictTree[str])",
44
"problem_number": "208",
55
"problem_title": "Implement Trie (Prefix Tree)",
66
"difficulty": "Medium",
@@ -14,7 +14,7 @@
1414
],
1515
"readme_constraints": "- `1 <= word.length, prefix.length <= 2000`\n- `word` and `prefix` consist only of lowercase English letters.\n- At most `3 * 10^4` calls **in total** will be made to `insert`, `search`, and `starts_with`.",
1616
"readme_additional": "",
17-
"solution_imports": "",
17+
"solution_imports": "from leetcode_py.data_structures import DictTree",
1818
"solution_methods": [
1919
{ "name": "__init__", "parameters": "", "return_type": "None", "dummy_return": "" },
2020
{ "name": "insert", "parameters": "word: str", "return_type": "None", "dummy_return": "" },

leetcode/implement_trie_prefix_tree/playground.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
},
6060
{
6161
"cell_type": "code",
62-
"execution_count": 4,
63-
"id": "8d00661e",
62+
"execution_count": 5,
63+
"id": "f3bac41e",
6464
"metadata": {},
6565
"outputs": [
6666
{
@@ -170,10 +170,10 @@
170170
"</svg>\n"
171171
],
172172
"text/plain": [
173-
"<solution.Trie at 0x1043da270>"
173+
"<solution.Trie at 0x10406a270>"
174174
]
175175
},
176-
"execution_count": 4,
176+
"execution_count": 5,
177177
"metadata": {},
178178
"output_type": "execute_result"
179179
}
@@ -184,7 +184,7 @@
184184
},
185185
{
186186
"cell_type": "code",
187-
"execution_count": 5,
187+
"execution_count": 4,
188188
"id": "test",
189189
"metadata": {},
190190
"outputs": [],
@@ -207,7 +207,7 @@
207207
"file_extension": ".py",
208208
"mimetype": "text/x-python",
209209
"name": "python",
210-
"nbconvert_exporter": "python",
210+
"nbconvert_exporter": "python3",
211211
"pygments_lexer": "ipython3",
212212
"version": "3.13.7"
213213
}

leetcode/implement_trie_prefix_tree/tests.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,6 @@ class TestImplementTriePrefixTree:
3030
[None, None, False, True, None, True, True],
3131
),
3232
(["Trie", "search", "starts_with"], [[], ["empty"], ["empty"]], [None, False, False]),
33-
(
34-
["Trie", "insert", "insert", "search", "search", "starts_with"],
35-
[[], ["cat"], ["car"], ["cat"], ["card"], ["ca"]],
36-
[None, None, None, True, False, True],
37-
),
38-
(
39-
["Trie", "insert", "search", "insert", "search", "starts_with"],
40-
[[], ["abc"], ["ab"], ["ab"], ["ab"], ["a"]],
41-
[None, None, False, None, True, True],
42-
),
43-
(
44-
["Trie", "insert", "insert", "insert", "search", "starts_with"],
45-
[[], [""], ["a"], ["ab"], [""], [""]],
46-
[None, None, None, None, True, True],
47-
),
48-
(
49-
["Trie", "insert", "search", "starts_with", "insert", "search"],
50-
[[], ["z"], ["z"], ["z"], ["zzz"], ["zzz"]],
51-
[None, None, True, True, None, True],
52-
),
53-
(
54-
["Trie", "insert", "insert", "search", "search", "starts_with", "starts_with"],
55-
[[], ["prefix"], ["prefixsuffix"], ["prefix"], ["prefixsuffix"], ["pre"], ["prefixs"]],
56-
[None, None, None, True, True, True, True],
57-
),
58-
(
59-
["Trie", "insert", "insert", "search", "starts_with"],
60-
[[], ["word"], ["word"], ["word"], ["wor"]],
61-
[None, None, None, True, True],
62-
),
63-
(
64-
["Trie", "insert", "search", "search", "starts_with", "starts_with"],
65-
[[], ["Word"], ["word"], ["Word"], ["W"], ["w"]],
66-
[None, None, False, True, True, False],
67-
),
68-
(
69-
["Trie", "insert", "insert", "search", "search", "search", "starts_with", "starts_with"],
70-
[[], ["a"], ["b"], ["a"], ["b"], ["c"], ["a"], ["b"]],
71-
[None, None, None, True, True, False, True, True],
72-
),
73-
(
74-
[
75-
"Trie",
76-
"insert",
77-
"insert",
78-
"insert",
79-
"insert",
80-
"search",
81-
"search",
82-
"search",
83-
"search",
84-
"search",
85-
"starts_with",
86-
"starts_with",
87-
],
88-
[
89-
[],
90-
["car"],
91-
["card"],
92-
["care"],
93-
["careful"],
94-
["car"],
95-
["card"],
96-
["care"],
97-
["careful"],
98-
["ca"],
99-
["car"],
100-
["care"],
101-
],
102-
[None, None, None, None, None, True, True, True, True, False, True, True],
103-
),
10433
],
10534
)
10635
@logged_test

0 commit comments

Comments
 (0)