递归(深度优先遍历)
package Search;
import java.util.LinkedList;
import java.util.Stack;
public class LongestIncreasingPathInMatrix {
/**
* 寻找一个矩阵中最长增长路径
* 深度搜索
*/
public static int longestIncreasingInMatrix(int[][] matrix, LinkedList<Integer> list){
if(matrix == null || matrix.length == 0 || matrix[0].length == 0){
return 0;
}
int max = 1;
boolean[][] flag = new boolean[matrix.length][matrix[0].length];
for(int i = 0; i < matrix.length; i++){
for(int j = 0; j < matrix[0].length; j++){
if(!flag[i][j]){
LinkedList<Integer> tmp = new LinkedList<>();
int len = longest(matrix,i,j,tmp,flag);
if(len > max){
max = len;
while(!list.isEmpty()){