public class Solution { public int MinimumTotal(IList> triangle) { if(triangle.Count == 0){ return 0; } if(triangle.Count == 1){ return triangle[0][0]; } var arr = new int[triangle.Count, triangle[triangle.Count - 1].Count]; arr[0,0] = triangle[0][0]; for(var i = 1;i < triangle.Count; i++) { var current = triangle[i]; arr[i,0] = current[0] + arr[i-1,0]; for(var j = 1;j < current.Count - 1; j++) { arr[i,j] = current[j] + Math.Min(arr[i-1,j],arr[i-1,j-1]); } arr[i,current.Count-1] = current[current.Count-1] + arr[i-1,current.Count-2]; } var len = arr.GetLength(1); var min = arr[len - 1,0]; for(var i = 1;i < len; i++){ if(min > arr[len - 1,i]){ min = arr[len - 1,i]; } } return min; } }