79. Word Search
题目
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.
For example,
Given board =
1 | [ |
word =”ABCCED” return true;
word= “SEE return true;
word=”ABCB” return false;
大意
从一个位置走到另一个位置,看能不能拼成给定的字符串,走过的不能重复。
答案
1 | class Solution { |
思路
使用深度优先搜索,同时再使用相同大小的visited用来标记是否访问过。
Author: corn1ng
Link: https://corn1ng.github.io/2017/11/19/算法/leetcode79/
License: 知识共享署名-非商业性使用 4.0 国际许可协议