【发布时间】:2018-05-07 05:42:08
【问题描述】:
我想通过计算 trie 中有多少单词来计算 trie 结构中有多少叶节点,但我的代码没有更新计数值,而是始终重置为 0。
int num = 0;
public int countLeafNodes() {
for (char c : children.keySet()) {
Trie node = children.get(c);
System.out.println(c);
if (node.isWord) {
num++;
System.out.println(num);
}
node.countLeafNodes();
}
return num;
}
【问题讨论】: