# 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.

public int minPathSum(int[][] grid) {

## 解法一：

### 思路：

grid[i][j] = Math.min(grid[i-1][j],grid[i][j-1]) + grid[i][j];

### Code:

public class Solution {
public int minPathSum(int[][] grid) {
int m = grid.length;
int n = grid[0].length;
for(int i = 0; i < m; i++){
for(int j = 0;j < n; j++){
if(i == 0 && j != 0){
grid[i][j] = grid[i][j] + grid[i][j - 1];
}
else if(i != 0 && j == 0){
grid[i][j] = grid[i][j] + grid[i - 1][j];
}
else if(i == 0 && j == 0){
grid[i][j] = grid[i][j];
}
else{
grid[i][j] = Math.min(grid[i-1][j],grid[i][j-1]) + grid[i][j];
}

}
}
return grid[m-1][n-1];
}
}

## 彩蛋：

#### LeetCode || Minimum Path Sum

2014-10-19 11:40:15

#### leetcode 64. Minimum Path Sum-最小路径和|动态规划

2016-05-31 20:11:51

#### LeetCode 64 — Minimum Path Sum（C++ Java Python）

2014-02-26 22:09:52

#### [LeetCode]64.Minimum Path Sum

2015-02-04 15:55:25

#### leetcode64-Minimum Path Sum(最小路径和)

2016-02-17 12:08:44

#### 【LeetCode-面试算法经典-Java实现】【064-Minimum Path Sum（最小路径和）】

2015-08-02 06:05:34

#### leetCode 64.Minimum Path Sum (最短路) 解题思路和方法

2015-07-17 16:25:43

#### LeetCode -- Triangle 路径求最小和（ 动态规划问题）

2014-05-25 18:10:15

#### (Java)LeetCode-64. Minimum Path Sum

2016-10-07 16:25:49

#### Leetcode 64. Minimum Path Sum 最小路径和 解题报告

2016-05-06 23:49:05