Using DP: easy to understand C++ code!


#1
int Solution::uniquePaths(int A, int B) {

vector <vector<int>> dp(A,vector<int>(B));
if (!A || !B)return 0;
for(int i = B-1; i >= 0 ; i --)
{
    dp[A-1][i]=1;
}
for (int i = A-1; i >= 0; i --)
{
    dp[i][B-1]=1;
}

for (int i = A-2; i >= 0; i --){
    for (int j = B-2; j >= 0; j--){
        dp[i][j] = dp[i+1][j] + dp[i][j+1];
    }
}

return dp[0][0];

}