问题:
Given an m x n board of characters and a list of strings words, return all words on the board.
Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
Example 1:
Input:
| |
Output:
| |
Example 2:

Input:
| |
Output:
| |
Constraints:
m == board.lengthn == board[i].length1 <= m, n <= 12board[i][j]is a lowercase English letter.1 <= words.length <= 3 * 1041 <= words[i].length <= 10words[i]consists of lowercase English letters.- All the strings of
wordsare unique.
解答:
深度优先遍历DFS。使用“#”标识了已经遍历的节点的信息,将单词存放到Trie,上下左右四个方向通过调用DFS递归函数在二维数组中进行查找匹配
| |
参考及引用
图片来自 twitter Ines B @moraimauy