Description
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring.
The same letter cell may not be used more than once.
Example:
1 | board = |
Constraints:
- board and word consists only of lowercase and uppercase English letters.
- 1 <= board.length <= 200
- 1 <= board[i].length <= 200
- 1 <= word.length <= 10^3
Difficulty: Medium
Code:
1 | class Solution { |
题意
给定一个2D的棋盘和一个单词,找出单词是否在网格出现。单词可以从有序相邻的单元格中构造,同一个字符只能用一次。
原二维数组就像一个迷宫,可以上下左右四个方向走,可以以每个数都作为起点来走。