|
| 1 | +<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> |
| 2 | + |
| 3 | +<p>The word can 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.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/word2.jpg" style="width: 322px; height: 242px;" /> |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" |
| 10 | +<strong>Output:</strong> true |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong class="example">Example 2:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/word-1.jpg" style="width: 322px; height: 242px;" /> |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE" |
| 17 | +<strong>Output:</strong> true |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 3:</strong></p> |
| 21 | +<img alt="" src="https://assets.leetcode.com/uploads/2020/10/15/word3.jpg" style="width: 322px; height: 242px;" /> |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB" |
| 24 | +<strong>Output:</strong> false |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p> </p> |
| 28 | +<p><strong>Constraints:</strong></p> |
| 29 | + |
| 30 | +<ul> |
| 31 | + <li><code>m == board.length</code></li> |
| 32 | + <li><code>n = board[i].length</code></li> |
| 33 | + <li><code>1 <= m, n <= 6</code></li> |
| 34 | + <li><code>1 <= word.length <= 15</code></li> |
| 35 | + <li><code>board</code> and <code>word</code> consists of only lowercase and uppercase English letters.</li> |
| 36 | +</ul> |
| 37 | + |
| 38 | +<p> </p> |
| 39 | +<p><strong>Follow up:</strong> Could you use search pruning to make your solution faster with a larger <code>board</code>?</p> |
0 commit comments