Algorithms, Part II - Week 4 - Boggle
根据规则找出尽可能多的单词,编写 Boggle 游戏的AI部分
使用 DFS 解决
public Iterable<String> getAllValidWords(BoggleBoard board) {
TreeSet<String> words = new TreeSet<>();
for (int i = 0; i < board.rows(); i++) {
for (int j = 0; j < board.cols(); j++) {
boolean[][] visited = new boolean[board.rows()][board.cols()];
dfs(board, i, j, words, visited, "");
}
}
return words;
}