-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
52 lines (47 loc) · 1.19 KB
/
Solution.java
File metadata and controls
52 lines (47 loc) · 1.19 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
package algorithmtest;
import java.util.LinkedList;
public class Solution {
public int longestIncreasingPath(int[][] matrix) {
if(matrix.length==0)
{
return 0;
}
for(int i=0;i<matrix.length;i++)
{
for (int j = 0; j < matrix[i].length; j++) {
LinkedList<Integer>temp=new LinkedList<Integer>();
helper329(matrix, i, j, temp,true);
}
}
return res329;
}
int res329=1;
public void helper329(int[][] matrix, int i,int j,LinkedList<Integer>temp,boolean first)
{
if(i<0||j<0||i>=matrix.length||j>=matrix[i].length||(!first&&temp.getLast()>=matrix[i][j]))
{
return;
}
if(first||temp.getLast()<matrix[i][j]){
temp.add(matrix[i][j]);
res329=Math.max(res329, temp.size());
helper329(matrix, i, j+1,temp,false);
helper329(matrix, i, j-1, temp,false);
helper329(matrix, i+1, j,temp,false);
helper329(matrix, i-1, j, temp,false);
temp.removeLast();
}
}
public void test(int []a)
{
a[0]=1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s =new Solution();
int [][]data={{6,8},{7,2}};
int [] a = new int[] {3};
//s.test(a);
System.out.println(a[0]);
}
}