标签:OLE div pre base describe mtab close imsi int
1 public class Solution { 2 public boolean dfs(int x, int y, char[] matrix, int rows, int cols, char[] str, int pos, boolean[][]vis) { 3 int [][]shift = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; 4 boolean flag = false; 5 if (pos == str.length) return true; 6 for (int i = 0; i < 4; ++i) { 7 int posx = x + shift[i][0]; 8 int posy = y + shift[i][1]; 9 if (flag) return true; 10 if (posx < rows && posy < cols && posx >= 0 && posy >= 0 && !vis[posx][posy]) { 11 char c = matrix[posx * cols + posy]; 12 if (c == str[pos]) { 13 vis[posx][posy] = true; 14 flag = flag || dfs(posx, posy, matrix, rows, cols, str, pos + 1, vis); 15 vis[posx][posy] = false; 16 } 17 } 18 } 19 return flag; 20 21 } 22 public boolean hasPath(char[] matrix, int rows, int cols, char[] str) 23 { 24 25 boolean [][]vis = new boolean [rows + 1][cols + 1]; 26 boolean flag = false; 27 28 for (int i = 0; i < rows; ++i) { 29 for (int j = 0; j < cols; ++j) { 30 char c = matrix[i * cols + j]; 31 if(flag) return true; 32 if (c == str[0]) { 33 vis[i][j] = true; 34 flag = flag || dfs(i, j, matrix, rows, cols, str, 1, vis); 35 vis[i][j] = false; 36 } 37 } 38 } 39 return flag; 40 } 41 42 43 }
标签:OLE div pre base describe mtab close imsi int
原文地址:https://www.cnblogs.com/hyxsolitude/p/12300983.html