文章目录
- 题目描述
- 解题思路
题目描述
https://leetcode.cn/problems/minimum-path-sum/
解题思路
问题类型:动态规划
private int MinPathSum(int[][] grid) {
for (int i = 0; i < grid.Length; i++) {
for (int j = 0; j < grid[i].Length; j++) {
if (i == 0 & j == 0) continue;
else if (i == 0) grid[i][j] += grid[i][j - 1];
else if (j == 0) grid[i][j] += grid[i - 1][j];
else grid[i][j] += Mathf.Min(grid[i - 1][j], grid[i][j - 1]);
}
}
return grid[grid.Length - 1][grid[0].Length - 1];
}