如果有人感兴趣的话,再具体讲解思路吧!
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
/**
* created by jiayaoguang at 2017年9月28日 敏感词过滤
*/
public class ACFind {
private final TrieNode root;
public static void main(String[] args) {
String[] keywords = new String[] { "人能世界那1大那大好人坏人1", "世界那1大那大好人坏人1", "能世界那1大那大好人坏人1", "界那1大那大好人坏人1",
"那1大那大好人坏人1", "1大那大好人坏人", "坏1人", "世界那大", "世界那么大" };
ACFind find = new ACFind(keywords);
int index = find.find("人能世界那1大那大好人坏人");
System.out.println(index);
}
public ACFind(String[] keywords) {
root = buildTree(keywords);
// printTree(root);
addFailNode(root);
}
/**
* 查找是否包含目标字符串
*/
public int find(String text) {
int len = text.length();
TrieNode node = root;
for (int index = 0; index < len; i