|
1 | 1 | [#0079-word-search] |
2 | | -= 79. Word Search |
| 2 | += 79. 单词搜索 |
3 | 3 |
|
4 | | -{leetcode}/problems/word-search/[LeetCode - Word Search^] |
| 4 | +https://leetcode.cn/problems/word-search/[LeetCode - 79. 单词搜索^] |
5 | 5 |
|
6 | | -Given a 2D board and a word, find if the word exists in the grid. |
| 6 | +给定一个 `m x n` 二维字符网格 `board` 和一个字符串单词 `word`。如果 `word` 存在于网格中,返回 `true` ;否则,返回 `false` 。 |
7 | 7 |
|
8 | | -The word can 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. |
| 8 | +单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。 |
9 | 9 |
|
10 | | -*Example:* |
| 10 | +*示例 1:* |
11 | 11 |
|
12 | | -[subs="verbatim,quotes,macros"] |
13 | | ----- |
14 | | -board = |
15 | | -[ |
16 | | - ['A','B','C','E'], |
17 | | - ['S','F','C','S'], |
18 | | - ['A','D','E','E'] |
19 | | -] |
20 | | -
|
21 | | -Given word = "*ABCCED*", return *true*. |
22 | | -Given word = "*SEE*", return *true*. |
23 | | -Given word = "*ABCB*", return *false*. |
24 | | ----- |
| 12 | +image::images/0079-01.jpg[{image_attr}] |
| 13 | + |
| 14 | +.... |
| 15 | +输入:board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" |
| 16 | +输出:true |
| 17 | +.... |
| 18 | + |
| 19 | +*示例 2:* |
| 20 | + |
| 21 | +image::images/0079-02.jpg[{image_attr}] |
| 22 | + |
| 23 | +.... |
| 24 | +输入:board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE" |
| 25 | +输出:true |
| 26 | +.... |
| 27 | + |
| 28 | +*示例 3:* |
| 29 | + |
| 30 | +image::images/0079-03.jpg[{image_attr}] |
| 31 | + |
| 32 | +.... |
| 33 | +输入:board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB" |
| 34 | +输出:false |
| 35 | +.... |
| 36 | + |
| 37 | +*提示:* |
| 38 | + |
| 39 | +* `m == board.length` |
| 40 | +* `n = board[i].length` |
| 41 | +* `1 \<= m, n \<= 6` |
| 42 | +* `1 \<= word.length \<= 15` |
| 43 | +* `board` 和 `word` 仅由大小写英文字母组成 |
| 44 | +
|
| 45 | +**进阶:**你可以使用搜索剪枝的技术来优化解决方案,使其在 `board` 更大的情况下可以更快解决问题? |
25 | 46 |
|
26 | 47 | == 思路分析 |
27 | 48 |
|
@@ -49,11 +70,24 @@ include::{sourcedir}/_0079_WordSearch.java[tag=answer] |
49 | 70 | include::{sourcedir}/_0079_WordSearch_2.java[tag=answer] |
50 | 71 | ---- |
51 | 72 | -- |
| 73 | +
|
| 74 | +三刷:: |
| 75 | ++ |
| 76 | +-- |
| 77 | +[{java_src_attr}] |
| 78 | +---- |
| 79 | +include::{sourcedir}/_0079_WordSearch_3.java[tag=answer] |
| 80 | +---- |
| 81 | +-- |
52 | 82 | ==== |
53 | 83 |
|
| 84 | + |
54 | 85 | == 参考资料 |
55 | 86 |
|
56 | | -. https://leetcode.cn/problems/word-search/solutions/2361646/79-dan-ci-sou-suo-hui-su-qing-xi-tu-jie-5yui2/?envType=study-plan-v2&envId=selected-coding-interview[79. 单词搜索 - 回溯,清晰图解^] |
| 87 | +. https://leetcode.cn/problems/word-search/solutions/2927294/liang-ge-you-hua-rang-dai-ma-ji-bai-jie-g3mmm/[79. 单词搜索 - 极致优化!代码击败接近 100%!^] |
| 88 | +. https://leetcode.cn/problems/word-search/solutions/2361646/79-dan-ci-sou-suo-hui-su-qing-xi-tu-jie-5yui2/[79. 单词搜索 - 回溯,清晰图解^] |
| 89 | +. https://leetcode.cn/problems/word-search/solutions/411749/shou-hua-tu-jie-79-dan-ci-sou-suo-dfs-si-lu-de-cha/[79. 单词搜索 - 「手画图解」回溯思路的形成与细节^] |
| 90 | +. https://leetcode.cn/problems/word-search/solutions/411613/dan-ci-sou-suo-by-leetcode-solution/[79. 单词搜索 - 官方题解^] |
57 | 91 |
|
58 | 92 |
|
59 | 93 |
|
0 commit comments