【发布时间】:2022-01-25 13:52:59
【问题描述】:
比如我想在trie中插入“几个”,但是不知道怎么做:
public void insertWord(String wordName){
for (int i = 0; i < wordName.length(); i++){
if( current.children[wordName.charAt(i) - 'a'] == null)
current.children[wordName.charAt(i) - 'a'] = new Node(wordName.charAt(i));
current = current.children[wordName.charAt(i) - 'a'];
}
}
我收到此错误:
线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:索引 -65 超出长度 29 的范围
数组长度等于29。
我该如何解决这个问题?
【问题讨论】:
-
您可以决定忽略它。 trie 中的任何内容都不会对任何值进行特殊处理。
标签: java dictionary trie