- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrie.cpp
More file actions
Latest commit
25 lines (21 loc) · 425 Bytes
/
Copy pathTrie.cpp
File metadata and controls
25 lines (21 loc) · 425 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
structTrieNode {
TrieNode* child[26];
int cnt;
TrieNode() {
for (int i = 0; i < 26; i++)
child[i] = NULL;
cnt = 0;
}
};
TrieNode* root = new TrieNode();
voidadd (const string& s) {
TrieNode* u = root;
for (char ch : s) {
int id = ch - 'a';
if (u -> child[id] == NULL) {
u -> child[id] = newTrieNode();
}
u = u -> child[id];
}
u -> cnt++;
}