We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parenteafd4b1 commit06b9f6bCopy full SHA for 06b9f6b
src/main/java/com/fishercoder/solutions/_329.java
@@ -6,13 +6,12 @@ public static class Solution1 {
6
finalint[]dirs =newint[]{0,1,0, -1,0};
7
8
publicintlongestIncreasingPath(int[][]matrix) {
9
-if (matrix ==null ||matrix.length ==0) {
10
-return0;
11
- }
+intm =matrix.length;
+intn =matrix[0].length;
12
intmax =0;
13
-int[][]cache =newint[matrix.length][matrix[0].length];
14
-for (inti =0;i <matrix.length;i++) {
15
-for (intj =0;j <matrix[0].length;j++) {
+int[][]cache =newint[m][n];
+for (inti =0;i <m;i++) {
+for (intj =0;j <n;j++) {
16
intlen =dfs(matrix,i,j,cache);
17
max =Math.max(len,max);
18
}
@@ -25,7 +24,7 @@ int dfs(int[][] matrix, int row, int col, int[][] cache) {
25
24
returncache[row][col];
26
27
intmax =1;
28
-for (inti =0;i <4;i++) {
+for (inti =0;i <dirs.length -1;i++) {
29
intnextRow =row +dirs[i];
30
intnextCol =col +dirs[i +1];
31
if (nextRow <0 ||nextRow >=matrix.length ||nextCol <0 ||nextCol >=matrix[0].length ||matrix[nextRow][nextCol] <=matrix[row][col]) {