Skip to content

Commit 7f7c431

Browse files
committed
Runtime: 196 ms (Top 48.11%) | Memory: 50.6 MB (Top 47.62%)
1 parent f1c3fe3 commit 7f7c431

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// Runtime: 196 ms (Top 48.11%) | Memory: 50.6 MB (Top 47.62%)
12
var longestIncreasingPath = function(matrix) {
23
const m = matrix.length, n = matrix[0].length;
34
const dp = new Array(m).fill(0).map(() => {
45
return new Array(n).fill(-1);
56
});
6-
7+
78
let ans = 0;
89
const dir = [0, -1, 0, 1, 0];
9-
10+
1011
const dfs = (x, y) => {
1112
if(dp[x][y] != -1) return dp[x][y];
12-
13+
1314
for(let i = 1; i <= 4; i++) {
1415
const [nx, ny] = [x + dir[i], y + dir[i - 1]];
1516
if(
@@ -20,17 +21,17 @@ var longestIncreasingPath = function(matrix) {
2021
dp[x][y] = Math.max(dp[x][y], 1 + dfs(nx, ny));
2122
}
2223
}
23-
24+
2425
if(dp[x][y] == -1) dp[x][y] = 1;
2526
ans = Math.max(ans, dp[x][y]);
2627
return dp[x][y];
2728
}
28-
29+
2930
for(let i = 0; i < m; i++) {
3031
for(let j = 0; j < n; j++) {
3132
if(dp[i][j] == -1) dfs(i, j);
3233
}
3334
}
34-
35+
3536
return ans;
36-
};
37+
};

0 commit comments

Comments
 (0)