https://leetcode-cn.com/problems/word-search/
深度优先遍历 + 添加现场
public boolean exist(char[][] board, String word) {char[] w = word.toCharArray();for (int i = 0; i < board.length; i++) {for (int j = 0; j < board[0].length; j++) {if (process(board, i, j, w, 0)) {return true;}}}return false;}private boolean process(char[][] board, int i, int j, char[] w, int k) {if (k == w.length) {return true;}if (i < 0 || i == board.length || j < 0 || j == board[0].length) {return false;}if (w[k] != board[i][j]) {return false;}char tmp = board[i][j];//不走回头路机制 --> 增加现场board[i][j] = 0;boolean ans = process(board, i - 1, j, w, k + 1)|| process(board, i + 1, j, w, k + 1)|| process(board, i, j - 1, w, k + 1)|| process(board, i, j + 1, w, k + 1);// 恢复现场board[i][j] = tmp;return ans;}
