Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06b9f6b

Browse files
refactor 329
1 parenteafd4b1 commit06b9f6b

File tree

1 file changed

+6
-7
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-7
lines changed

‎src/main/java/com/fishercoder/solutions/_329.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ public static class Solution1 {
66
finalint[]dirs =newint[]{0,1,0, -1,0};
77

88
publicintlongestIncreasingPath(int[][]matrix) {
9-
if (matrix ==null ||matrix.length ==0) {
10-
return0;
11-
}
9+
intm =matrix.length;
10+
intn =matrix[0].length;
1211
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++) {
12+
int[][]cache =newint[m][n];
13+
for (inti =0;i <m;i++) {
14+
for (intj =0;j <n;j++) {
1615
intlen =dfs(matrix,i,j,cache);
1716
max =Math.max(len,max);
1817
}
@@ -25,7 +24,7 @@ int dfs(int[][] matrix, int row, int col, int[][] cache) {
2524
returncache[row][col];
2625
}
2726
intmax =1;
28-
for (inti =0;i <4;i++) {
27+
for (inti =0;i <dirs.length -1;i++) {
2928
intnextRow =row +dirs[i];
3029
intnextCol =col +dirs[i +1];
3130
if (nextRow <0 ||nextRow >=matrix.length ||nextCol <0 ||nextCol >=matrix[0].length ||matrix[nextRow][nextCol] <=matrix[row][col]) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp