public class Find2 {
public int[] dx={1,-1,0,0};
public int[] dy={0,0,1,-1};
class Trie{
Trie[] tries;
String isEnd;
public Trie(){
tries = new Trie[26];
}
}
public boolean[][] vis; //是否判断过
public List<String> res; //答案
public void insert(String word, Trie root){
Trie t = root;
for(int i = 0;i < word.length();i++){
int index = word.charAt(i)-'a';
if(t.tries[index] == null){
t.tries[index] = new Trie();
}
t = t.tries[index];//跳到子节点
}
t.isEnd = word;
}
public List<String> findWords(char[][] board, String[] words) {
//先把单词存入字典树当中
Trie root=new Trie();
for(String word:words){
insert(word,root);
}
res=new ArrayList<String>();
vis=new boolean[boar
Java实现 LeetCode 212 单词搜索 II
最新推荐文章于 2020-06-01 22:22:05 发布