每天刷一道牛客题霸-第15天-矩阵最小路径和

题目

https://www.nowcoder.com/practice/7d21b6be4c6b429bb92d219341c4f8bb?tpId=190&&tqId=35224&rp=1&ru=/ta/job-code-high-rd&qru=/ta/job-code-high-rd/question-ranking

import java.util.*;


public class Solution {
    /**
     *
     * @param matrix int整型二维数组 the matrix
     * @return int整型
     */
    public static int minPathSum (int[][] matrix) {
        if (matrix.length == 0){
            return 0;
        }
        for (int i = 1 ;i < matrix[0].length ; i++){
            matrix[0][i] += matrix[0][i-1];
        }
        for (int i = 1; i < matrix.length ; i++){
            matrix[i][0] += matrix[i-1][0];
        }
        for (int i = 1 ; i < matrix.length ; i++){
            for (int j = 1 ; j < matrix[i].length ; j++){
                matrix[i][j] += Math.min(matrix[i][j-1],matrix[i-1][j]);
            }
        }
        return matrix[matrix.length-1][matrix[0].length-1];
    }


}
#题解##牛客题霸#
全部评论
113213124244324点到反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复发发发反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复反反复复发反反复复
点赞 回复 分享
发布于 2020-12-18 22:39
点赞 回复 分享
发布于 2020-12-19 11:12

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务