LeetCode Minimum Path Sum
2014-10-18 19:23
260 查看
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.
Note: You can only move either down or right at any point in time.
public class Solution { public int minPathSum(int[][] grid) { if (grid==null) { return 0; } int minpath=0; int m=grid.length; int n=grid[0].length; int[][] sumpath=new int[m] ; sumpath[0][0]=grid[0][0]; for (int j = 1; j < n; j++) { sumpath[0][j]=sumpath[0][j-1]+grid[0][j]; } for (int i = 1; i < m; i++) { sumpath[i][0]=sumpath[i-1][0]+grid[i][0]; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { sumpath[i][j]=grid[i][j]+Math.min(sumpath[i][j-1], sumpath[i-1][j]); } } return sumpath[m-1][n-1]; } }
相关文章推荐
- 【LeetCode】 064. Minimum Path Sum
- LeetCode Minimum Path Sum
- 【LeetCode-面试算法经典-Java实现】【064-Minimum Path Sum(最小路径和)】
- LeetCode | Minimum Path Sum(最小路径和)
- 【LeetCode】Minimum Path Sum
- Minimum Path Sum - LeetCode
- 【LeetCode】Minimum Path Sum
- 【题解】【矩阵】【DP】【Leetcode】Minimum Path Sum
- 【LeetCode】Minimum Path Sum
- 【LeetCode-动态规划】Minimum Path Sum【重要->状态转移方程取最值】
- LeetCode题解——Minimum Path Sum
- LeetCode 64 Minimum Path Sum(动态规划)
- leetcode - Minimum Path Sum
- [LeetCode56]Minimum Path Sum
- 【LeetCode】【Python】Minimum Path Sum
- Minimum Path Sum leetcode java
- LeetCode--Minimum Path Sum
- LeetCode算法题——Minimum Path Sum
- 【LeetCode】Minimum Path Sum 解题报告
- leetcode | Minimum Path Sum