← 返回 uber 的题目列表Word Search
类型:online_judge
Problem: Word Search
Given an m x n character grid board and a string word, determine whether word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells. Adjacent cells are horizontally or vertically neighboring. The same cell may not be used more than once in the same matching path.
Input Format for Testing
The first line contains two integers m n, the number of rows and columns.
The next m lines each contain a string of length n, representing one row of the board.
The last line contains the string word.
Output Format
Print true if word exists; otherwise print false.
Constraints
1 <= m, n <= 6
1 <= len(word) <= 15
board[i][j] and word consist of English letters.
Example
Input:
3 4
ABCE
SFCS
ADEE
ABCCED
Output:
true
Example
Input
3 4
ABCE
SFCS
ADEE
ABCCED
Output
true