题目地址: https://leetcode.com/problems/triangle/
修改了几次,但提交一直提示Runtime Error
int minimumTotal(int **triangle, int numRows) {
int row = 0;
int col = 0;
int current = 0;
int *Min = malloc((numRows + 1) * sizeof(int));
for (row = 0; row <= numRows; row++)
{
/* code */
Min[row] = 0;
}
for (row = numRows - 1; row >= 0; row--)
{
/* code */
for (col = 0; col <= row; col++)
{
/* code */
current = *((int *)triangle + row * numRows + col);
Min[col] = ((Min[col] > Min[col + 1]) ? Min[col + 1] : Min[col]) + current;
}
}
return Min[0];
}
修改了几次,但提交一直提示Runtime Error
int minimumTotal(int **triangle, int numRows) {
int row = 0;
int col = 0;
int current = 0;
int *Min = malloc((numRows + 1) * sizeof(int));
for (row = 0; row <= numRows; row++)
{
/* code */
Min[row] = 0;
}
for (row = numRows - 1; row >= 0; row--)
{
/* code */
for (col = 0; col <= row; col++)
{
/* code */
current = *((int *)triangle + row * numRows + col);
Min[col] = ((Min[col] > Min[col + 1]) ? Min[col + 1] : Min[col]) + current;
}
}
return Min[0];
}