LeetCode #62 Unique Paths
作者:
刘煌旭 | 来源:发表于
2021-04-23 18:14 被阅读0次

Unitque_Path_1.png

u_p_2.png
/**
* Abstract: A DP problem, immediately from the problem specs.
*/
int uniquePaths(int m, int n) {
int **dp = (int**)malloc((m + 1) * sizeof(*dp));
for (int i = 1; i <= m; i++) {
dp[i] = (int*)malloc((n + 1) * sizeof(int));
for (int j = 1; j <= n; j++) {
if (i == 1 || j == 1) {
dp[i][j] = 1;
} else {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
}
return dp[m][n];
}
本文标题:LeetCode #62 Unique Paths
本文链接:https://www.haomeiwen.com/subject/knqhrltx.html
网友评论