-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution47.java
More file actions
23 lines (21 loc) · 787 Bytes
/
Solution47.java
File metadata and controls
23 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public int maxValue(int[][] grid) {
int row = grid.length;
int col = grid[0].length;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (i == 0 && j == 0) {
continue;
} else if (i == 0 && j != 0) {
grid[i][j] += grid[i][j - 1];
} else if (i != 0 && j == 0) {
grid[i][j] += grid[i - 1][j];
} else {
grid[i][j] += Math.max(grid[i - 1][j], grid[i][j - 1]);
}
}
}
return grid[row - 1][col - 1];
}
}
// https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/solution/mian-shi-ti-47-li-wu-de-zui-da-jie-zhi-dong-tai-gu/