forked from zhangwg1990/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path64.c
More file actions
24 lines (21 loc) · 628 Bytes
/
64.c
File metadata and controls
24 lines (21 loc) · 628 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
int minPathSum(int** grid, int gridRowSize, int gridColSize) {
int i, res = 0;
int tmp1, tmp2;
if (1 == gridRowSize) {
for (i = 0; i < gridColSize; ++i) res += grid[0][i];
return res;
} else if (1 == gridColSize) {
for (i = 0; i < gridRowSize; ++i) res += grid[i][0];
return res;
} else {
tmp1 = minPathSum(grid, gridRowSize, gridColSize - 1);
tmp2 = minPathSum(grid, gridRowSize - 1, gridColSize);
res = tmp1 < tmp2 ? tmp1 : tmp2;
return res + grid[gridRowSize - 1][gridColSize - 1];
}
}
int main()
{
return 0;
}