← 返回 uber 的题目列表Word Search in a Straight Line (8 Directions, No Turns)
类型:online_judge
Given an m x n grid of characters board and a string word, determine whether word can be found in the grid along a straight line:
Choose any starting cell.
Choose a fixed direction among 8 directions (horizontal, vertical, or diagonal).
Move consecutively for len(word) characters in that direction (no turns allowed).
Return true if any such straight-line path spells word, otherwise return false.
Constraints
1 <= m, n <= 200
1 <= len(word) <= max(m,n)
Example
Grid:
A B C D
E F G H
I J K L
word = FGK => true (start at F, direction down)
word = ABF => false (would require a turn)
Example
Input
3 4
ABCD
EFGH
IJKL
FGK
Output
true