-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path472.cpp
More file actions
executable file
·33 lines (32 loc) · 930 Bytes
/
472.cpp
File metadata and controls
executable file
·33 lines (32 loc) · 930 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
26
27
28
29
30
31
32
33
class Solution {
public:
struct TreeNode{
int end;
TreeNode* child[26];
TreeNode():end(0){
for (int i = 0; i < 26; i++)
child[i] = nullptr;
}
}
int res = 0;
void dfs(TreeNode* root){
}
vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {
TreeNode* root = new TreeNode();
for (auto word : words){
TreeNode* cur = root;
for (int i = 0; i < word.size(); i++){
if (cur->child[word[i] - 'a'] == nullptr){
cur->child[word[i] - 'a'] = new TreeNode();
cur = cur->child[word[i] - 'a'];
}else{
cur = cur->child[word[i] - 'a'];
}
if (i == word.size() - 1){
cur->end += 1;
}
}
}
//dfs the trie
}
};