using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param matrix int整型二维数组 the matrix * @return int整型 */ public int minPathSum (List<List<int>> matrix) { int m = matrix[0].Count; int n = matrix.Count; int[] res = new int[m]; res[0] = matrix[0][0]; for(int i = 1; i < m; i++){ res[i] = res[i - 1] + matrix[0][i]; //Console.WriteLine(i); } for(int j = 1; j < n; j++){ //Console.WriteLine(j); res[0] = res[0] + matrix[j][0]; for(int i = 1; i < m; i++){ //Console.WriteLine(i); res[i] = Math.Min(res[i - 1], res[i]) + matrix[j][i]; } } return res[m - 1]; } }