We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f335134 commit 87be8d3Copy full SHA for 87be8d3
problems/472.concatenated-words.md
@@ -129,15 +129,16 @@ class Trie:
129
130
class Solution:
131
def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:
132
- self.trie = Trie()
+ trie = Trie()
133
res = []
134
-
135
- for word in words:
136
- self.trie.insert(word)
+ words.sort(key=len)
137
for word in words:
138
- if self.trie.cntWords(word) >= 2:
+ if trie.cntWords(word) >= 2:
139
res.append(word)
+ else:
+ trie.insert(word)
140
return res
141
+
142
```
143
144
## 相关题目
0 commit comments