Skip to content

Commit 87be8d3

Browse files
author
robot
committed
fix: TLE
1 parent f335134 commit 87be8d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

problems/472.concatenated-words.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,16 @@ class Trie:
129129

130130
class Solution:
131131
def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:
132-
self.trie = Trie()
132+
trie = Trie()
133133
res = []
134-
135-
for word in words:
136-
self.trie.insert(word)
134+
words.sort(key=len)
137135
for word in words:
138-
if self.trie.cntWords(word) >= 2:
136+
if trie.cntWords(word) >= 2:
139137
res.append(word)
138+
else:
139+
trie.insert(word)
140140
return res
141+
141142
```
142143

143144
## 相关题目

0 commit comments

Comments
 (0)