64. Minimum Path Sum

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.

一刷
题解:
类似于Dijkstra's algorithm, 创建新的矩阵(或者in-place),每个grid内存有到该点最小sum

Time Complexity - O(mn), Space Complexity - O(1)。

public class Solution {
    public int minPathSum(int[][] grid) {
        int n = grid.length;
        int m = grid[0].length;
        int[][] dp = new int[n][m];
        for(int i=0; i

还有一个滚动数组的思路,留到二刷

你可能感兴趣的:(64. Minimum Path Sum)