leetcode64.最小路径和

`private int m,n;
private int[] dx = {-1, 0, 1, 0};
private int[] dy = {0, -1, 0, 1};

public int minPathSum(int[][] grid) {
m = grid.length;
n = grid[0].length;
List<List> ans = new ArrayList<>();
List path = new ArrayList<>();
boolean[][] visited= new boolean[m][n];
dfs(0,0, grid, visited, path, ans);
int maxValue = Integer.MAX_VALUE;

for(List<Integer> onePath: ans) {
    int sum = 0;
    //System.out.println(onePath);
    for(int value: onePath) sum += value;
    maxValue = Math.min(sum, maxValue);
}
return maxValue;`
posted @ 2022-02-01 18:10  明卿册  阅读(22)  评论(0编辑  收藏  举报