← 返回 uber 的题目列表Word Search (Grid DFS Backtracking)
类型:online_judge
Given an m x n grid of characters board and a string word, determine whether word can be formed by sequentially adjacent cells (up, down, left, right).
Rules:
You may move only to horizontally or vertically adjacent cells.
The same cell may be used at most once in a single path.
Return true/false.
Constraints
1 <= m, n <= 20
1 <= len(word) <= m*n
Examples
Input:
board =
[[A,B,C,E], [S,F,C,S], [A,D,E,E]]
word = ABCCED
Output: true
Input same board, word = ABCB
Output: false
Example
Input
3 4
ABCE
SFCS
ADEE
ABCCED
Output
true