Skip to content

Commit 9e51072

Browse files
authored
Update WordDictionary.kt
1 parent ff10207 commit 9e51072

File tree

1 file changed

+0
-5
lines changed
  • src/main/kotlin/g0201_0300/s0211_design_add_and_search_words_data_structure

1 file changed

+0
-5
lines changed

src/main/kotlin/g0201_0300/s0211_design_add_and_search_words_data_structure/WordDictionary.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ class WordDictionary {
1313

1414
fun addWord(word: String) {
1515
var p = trieTree
16-
1716
for (w in word) {
1817
val i = w - 'a'
1918
if (p.children[i] == null) p.children[i] = TrieNode()
2019
p = p.children[i]!!
2120
}
22-
2321
p.isWord = true
2422
}
2523

2624
fun search(word: String): Boolean {
2725
fun dfs(p: TrieNode?, start: Int): Boolean {
2826
if (p == null) return false
29-
3027
if (start == word.length) return p.isWord
31-
3228
if (word[start] == '.') {
3329
for (i in 0..25) {
3430
if (dfs(p.children[i], start + 1)) {
@@ -41,7 +37,6 @@ class WordDictionary {
4137
return dfs(p.children[i], start + 1)
4238
}
4339
}
44-
4540
return dfs(trieTree, 0)
4641
}
4742
}

0 commit comments

Comments
 (0)