Simple C++ Solution memoization


#1

int mat[10001][10001];

int count_(int n, int m){

if(n == 0 || m == 0)
    return mat[n][m] = 1;

if(mat[n][m] != -1)
    return mat[n][m];

return mat[n][m] = count_(n-1,m)+count_(n, m-1);

}

int Solution::uniquePaths(int n, int m) {

for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
        mat[i][j] = -1;


int total = count_( n-1, m - 1);
return mat[n-1][m-1];

}