【算法】LeetCode62. 不同路径(java)
很明显动态规划题, 写了一个递归,时间复杂度太高,可以参考=-=
class Solution {
int count=0;
public int uniquePaths(int m, int n) {
go(m,n,0,0);
return count;
}
public void go(int m,int n,int x,int y){
if(x==n-1&&y==m-1){
count++;
return;
}
if(x!=n-1){
go(m, n, x+1, y);
}
if(y!=m-1){
go(m, n, x, y+1);
}
}
}
动态规划:
class Solution {
public int uniquePaths(int m, int n) {
共有 0 条评论