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 class Solution {
public int minPathSum(int[][] grid) {
if(grid==null || grid.length== || grid[].length==)return ;
int dp[][]=new int[grid.length][grid[].length];
dp[][]=grid[][];
for(int i=;i<grid.length;i++)dp[i][]=dp[i-][]+grid[i][];
for(int j=;j<grid[].length;j++)dp[][j]=dp[][j-]+grid[][j];
for(int i=;i<grid.length;i++)
{
for(int j=;j<grid[].length;j++)
{
dp[i][j]=Math.min(dp[i-][j], dp[i][j-])+grid[i][j];
}
}
return dp[dp.length-][dp[].length-];
}
}