Open GH1995 opened 5 years ago
If you exam each word one by one, you will have to always start from the first letter of each word. It will be slow for words that share prefix (e.g. "aaaaaaaaab" and "aaaaaaaaac"). Trie will accelerate the DFS by not repeating finding the shared prefix.
这是一道非常不错的题目
依次登场的变量有visited
数组,方向数组,
两层循环遍历数组位置
找到新位置
p
往下走一步,相当于s
前进一步,拓展新位置的状态
212. Word Search II
Difficulty: Hard
Given a 2D board and a list of words from the dictionary, find all words in the board.
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
Example:
Note:
a-z
.words
are distinct.Solution
Language: C++