阅读背景:

[leetcode] 62. 不同路径

来源:互联网 

62. 不同路径

我们直接用递归来模拟

class Solution {

    public static int cnt;

    public int uniquePaths(int m, int n) {
        cnt = 0;
        dfs(1, 1, m, n);
        return cnt;
    }

    public void dfs(int i, int j, int m, int n) {
        if (i == m && j == n) {
            cnt++;
            return;
        }
        if ((j + 1) <= n)
            dfs(i, j + 1, m, n);
        if ((i + 1) <= m)
            dfs(i + 1, j, m, n);
    }
}class Solution {

    pu



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: