In this way it's much easier to explain


  • 0
    P

    public class Solution {public int uniquePaths(int m, int n) {
    if (m <= 1 || n <= 1)
    return 1;
    int[][] dp = new int[m][n];
    for (int i = m - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
    if (i == m - 1 || j == n - 1) {
    dp[i][j] = 1;
    }
    else dp[i][j] = dp[i + 1][j] + dp[i][j + 1];
    }
    }
    return dp[0][0];
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.