# 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];
}
}

• 本文已收录于以下专栏：

## Leetcode64 Minimum Path Sum

Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to...

## leetcode[63] Minimum Path Sum 动态规划

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which...

## LeetCode刷题（C++）——Minimum Path Sum（Medium）

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which...

## LeetCode: Minimum Path Sum [063]

【题目】 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom righ...

## leetcode Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)