64. Minimum Path Sum
Description:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.
Example:
Input: [ [1,3,1], [1,5,1], [4,2,1] ] Output: 7 Explanation: Because the path 1→3→1→1→1 minimizes the sum.
解题思路:
(1) 递归法
问题分析:
1)假如我们就在最右下角的格子(也可以想象成网格只有一个格子),那么最短路径和就是格子中的值;
2)假如我们在最后一行的格子中,假如是grid[grid.length - 1][col],那么从这个点出发到最右下角的最小路径和就是它本身加上它右边的格子到最右下角的最小路径和。
3)最后一列和最后一行是同理的。
4)一个普通的位置,它到最右下角的最小路径和是多少呢,是它
LeetCode 64题最小路径和解题思路

这篇博客介绍了LeetCode第64题的解决方案,包括递归法、记忆化搜索和动态规划法。通过分析网格中从左上角到右下角的最小路径和,探讨了不同解题思路的实现细节,提供了AC代码示例。
最低0.47元/天 解锁文章
285

被折叠的 条评论
为什么被折叠?



