题解 | #不同路径的数目(一)#
不同路径的数目(一)
http://www.nowcoder.com/practice/166eaff8439d4cd898e3ba933fbc6358
原理:使用递归的方法(没用动态规划),直接暴力求解(时间复杂度有点大了。。。)
public class Solution {
public int findPaths (int x, int y, int m, int n) {
if (x==m || y==n) //接近终点则说明路径可行
return 1;
return findPaths(x+1, y, m, n)+findPaths(x, y+1, m, n); //从点的左、右同时出发寻找路径
}
public int uniquePaths (int m, int n) {
// write code here
return findPaths(1, 1, m, n);
}
}