-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathHasPath.java
40 lines (30 loc) · 1.06 KB
/
HasPath.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*矩阵中的路径:这个有点 还没搞懂 , 等脑袋清醒一点时候再来看这个*/
public class HasPath {
private final static int[][] next = {{0,-1},{0,1},{-1,0},{1,0}};
private int rows;
private int cols;
public boolean hasPath(String val,int rows,int cols,String path){
if (rows == 0 || cols == 0) return false;
this.rows = rows;
this.cols = cols;
char[] array = val.toCharArray();
// 建立字符串矩阵
char[][] matrix = buildMatrix(array);
// 路径字符串数组
char[] pathList = path.toCharArray();
boolean[][] marked = new boolean[rows][cols];
for (int i = 0; i < rows; i++) {
}
return false;
}
// 建立矩阵
public char[][] buildMatrix(char[] array){
char[][] matrix = new char[rows][cols];
for (int r = 0,idx = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
matrix[r][c] = array[idx++];
}
}
return matrix;
}
}