class Solution {
public int maxValue(int[][] grid) {
// 1、找到矩阵的宽度
int row=grid.length;
int col=grid[0].length;
//2、把第一行第一列处理好
for(int i=1;i<row;i++){
grid[i][0]=grid[i-1][0]+grid[i][0];
}
for(int j=1;j<col;j++){
grid[0][j]=grid[0][j-1]+grid[0][j];
}
//3、把中间的处理好
for(int i=1;i<row;i++){
for(int j=1;j<col;j++){
grid[i][j]=Math.max(grid[i-1][j],grid[i][j-1])+grid[i][j];
}
}
return grid[row-1][col-1];
}
}
03-22
239
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-08
381
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-07
349
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)