leetcode-62-不同路径
//dp,AC
class Solution {
public:
int uniquePaths(int m, int n) {
vector<int> row(m, 1);
vector<vector<int>> dp(n, row);
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
}
}
return dp[n - 1][m - 1];
}
};
int main() {
Solution sol;
int n = 2, m=3;
cout << sol.uniquePaths(n, m) << endl;
return 0;
}
//递归,未AC,超时
class Solution {
public:
int helper(vector<int> point, vector<int> target, long long int &time) {
if (point == target) time++;
if (point[0] < target[0]) {
//point[0]++;
helper({ point[0] + 1, point[1] }, target, time);
}
if (point[1] < target[1]) {
//point[1]++;
helper({point[0], point[1]+1}, target, time);
}
return 0;
}
int uniquePaths(int m, int n) {
long long int time=0;
helper({ 1,1 }, { m,n }, time);
return time;
}
};
- LeetCode62-不同路径
- leetcode62.不同路径
- [LeetCode]62 不同的路径总数
- LeetCode 62.不同路径
- LeetCode62/63. 不同路径问题(python)
- Leetcode-62.不同路径
- LeetCode刷题笔记 62.不同路径
- leetcode 62.不同路径
- 62. 不同路径
- LeetCode --- 62. 不同路径
- LeetCode题库解答与分析——#62. 不同路径UniquePaths
- 62. 不同路径
- 不同路径(LeetCode)
- LeetCode题库解答与分析——#63.不同路径IIUniquePathsII
- leetcode 62. 不同路径
- LeetCode刷题——动态规划,No.62不同路径
- Leetcode 62&63&64 不同路径 Java
- leetcode62. 不同路径(dp)
- [LeetCode] Unique Paths 不同的路径
- LeetCode--不同路径(动态规划)