我的LeetCode代码仓:https://github.com/617076674/LeetCode
原题链接:https://leetcode-cn.com/problems/word-search-ii/description/
题目描述:
知识点:回溯、Trie
思路一:LeetCode079——单词搜索的加强版
时间复杂度是O(s),其中s为words数组中的字符总数。空间复杂度是O(mn),其中m为board数组的行数,n为board数组的列数。
JAVA代码:
public class Solution {
boolean[][] flag;
int[][] directions = {
{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
private boolean exist(char[][] board, String word) {
int m = board.length;
if(m == 0