每日一题 2019 - 04 - 07
题目:
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:
1 | Input: |
解法:
这个让我们求出从地图左上角到右下角的最短路径,最简单的方法就是动态规划的思想,使用 now[width+1][length+1]
记录下走到当前路径下的最大代价,找出递推关系:
1 | if( now[i-1][j] >= now[i][j-1] ) |
即可完成题解
代码:
1 | class Solution { |