我想知道如何在n x m矩阵的数组中存储从左上到右下的所有路径。我只能打印出我无法将它们存储在数组中的路径。这就是我现在所拥有的
public static String printAllPaths(int currX, int currY, String path) throws IOException{
if(currX == d-1){
for(int j=currY;j<=d-1;j++){
path = path + grid[currX][j];
}
//System.out.println(path);
return path;
}
if(currY == d-1){
for(int i=currX;i<=d-1;i++){
path = path + grid[i][currY];
}
//System.out.println(path);
return path;
}
path = path + grid[currX][currY];
printAllPaths(currX+1, currY, path);
return printAllPaths(currX, currY+1, path);
}