LetCode 64. 最小路径和

static int x=[](){
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}();
class Solution {
public:
    int minPathSum(vector<vector<int>>& grid) {
        int row = grid.size();
        int col = grid[0].size();
        for (int i = 1; i < row; i++)
            grid[i][0] += grid[i - 1][0];
        for (int i = 1; i < col; i++)
            grid[0][i] += grid[0][i - 1];
        for (int i = 1; i < row; i++)
            for (int j = 1; j < col; j++)
                grid[i][j] += min(grid[i - 1][j], grid[i][j - 1]);
        return grid[row - 1][col - 1];
    }
};

猜你喜欢

转载自blog.csdn.net/wbb1997/article/details/81005646
今日推荐