File tree Expand file tree Collapse file tree 1 file changed +0
-5
lines changed
src/main/kotlin/g0201_0300/s0211_design_add_and_search_words_data_structure Expand file tree Collapse file tree 1 file changed +0
-5
lines changed Original file line number Diff line number Diff line change @@ -13,22 +13,18 @@ class WordDictionary {
13
13
14
14
fun addWord (word : String ) {
15
15
var p = trieTree
16
-
17
16
for (w in word) {
18
17
val i = w - ' a'
19
18
if (p.children[i] == null ) p.children[i] = TrieNode ()
20
19
p = p.children[i]!!
21
20
}
22
-
23
21
p.isWord = true
24
22
}
25
23
26
24
fun search (word : String ): Boolean {
27
25
fun dfs (p : TrieNode ? , start : Int ): Boolean {
28
26
if (p == null ) return false
29
-
30
27
if (start == word.length) return p.isWord
31
-
32
28
if (word[start] == ' .' ) {
33
29
for (i in 0 .. 25 ) {
34
30
if (dfs(p.children[i], start + 1 )) {
@@ -41,7 +37,6 @@ class WordDictionary {
41
37
return dfs(p.children[i], start + 1 )
42
38
}
43
39
}
44
-
45
40
return dfs(trieTree, 0 )
46
41
}
47
42
}
You can’t perform that action at this time.
0 commit comments