0%

### 题目描述

Given an `m x n` grid of characters `board` and a string `word`, return `true` if `word` exists in the grid.

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.

### 例子

#### 例子 1

Input: `board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"`
Output: `true`

#### 例子 2

Input: `board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"`
Output: `true`

#### 例子 3

Input: `board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCB"`
Output: `false`

• Could you use search pruning to make your solution faster with a larger `board`?

### Constraints

• `m == board.length`
• `n = board[i].length`
• `1 <= m, n <= 6`
• `1 <= word.length <= 15`
• `board` and `word` consists of only lowercase and uppercase English letters.

### 解题思路

• 到达目标单词末尾，返回 `true`
• 中间任何一个位置，如果索引位置越界、当前位置已经被使用过、当前位置字母不是要目标字母，返回 `false`

• 时间复杂度: `O(2^mn)`
• 空间复杂度: `O(mn)`

GitHub 代码同步地址： 79.WordSearch.cpp

GitHub: Leetcode-C++-Solution