【leetcode】【64】Minimum Path Sum
来源:互联网 发布:青岛知行国际派遣公司 编辑:程序博客网 时间:2024/04/29 16:33
一、问题描述
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.
二、问题分析
还是dynamic programing。与【leetcode】【62】Unique Paths类似。
三、Java AC代码
public int minPathSum(int[][] grid) {if (grid==null || grid.length==0) {return 0;}int row = grid.length;int col = grid[0].length;int[][] dp = new int[row][col];dp[0][0] = grid[0][0];for (int i = 1; i < row; i++) {dp[i][0] = dp[i-1][0]+grid[i][0];}for (int i = 1; i < col; i++) {dp[0][i] = dp[0][i-1]+grid[0][i];}for (int i = 1; i < row; i++) {for (int j = 1; j < col; j++) {dp[i][j] = Math.min(dp[i-1][j], dp[i][j-1])+grid[i][j];}}return dp[row-1][col-1];}
0 0
- LeetCode 64: Minimum Path Sum
- [leetcode 64] Minimum Path Sum
- [LeetCode 64]Minimum Path Sum
- leetcode || 64、Minimum Path Sum
- Minimum Path Sum - LeetCode 64
- Minimum Path Sum leetcode 64
- leetcode-64-Minimum Path Sum
- Leetcode 64(Minimum Path Sum)
- LeetCode(64) Minimum Path Sum
- Leetcode #64 Minimum Path Sum
- leetcode 64: Minimum Path Sum
- Leetcode#64||Minimum Path Sum
- LeetCode 64: Minimum Path Sum
- 【LEETCODE】64-Minimum Path Sum
- 【leetcode】【64】Minimum Path Sum
- LeetCode 64 - Minimum Path Sum
- LeetCOde 64 Minimum Path Sum
- leetcode-64:Minimum Path Sum
- Javascript异步编程的4种方法
- 使用Github Pages建独立博客
- IOS 第三方库----常用第三方库
- 大数据量数据库优化
- SQL Server导入数据报错"无法在只读列“Id”中插入数据"
- 【leetcode】【64】Minimum Path Sum
- 如何在2015年后的MacBook Air上安装双系统
- SAX,DOM,Pull的比较
- Markdown——入门指南
- java httpclient 上传文件 服务器 servlet 接收
- UITableView学习笔记
- Java之——程序员容易犯的常见十大错误
- DIV+CSS 中的 overflow:hidden清楚浮动作用
- 一款可以限定选择区域的日期控件