赞
踩
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.
将矩阵中的每一个字符当作起点与word做匹配,然后对其上下左右分别调用dfs,如果有满足条件的则返回true,将矩阵遍历完之后还是没有满足条件的则返回false
public boolean exist(char[][] board, String word) {
if (board == null || board.length == 0)
return false;
int n = board.length, m = board[0].length;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。