Why not use long long in this problem?


  • 0
    C

    I get -1080099800 when I run test case 99 99. And I also find my program will return a negative number of test case 40 56 in my own environment in spite of using long long.Who can tell me why?Here are my code.

    #define maxn 105
    int f[maxn][maxn];
    int  uniquePaths(int m, int n) {
        if(f[m][n]) return f[m][n];
        if(m == 1 && n == 1) return 1;
        else if(m == 1) f[m][n] = uniquePaths(m, n - 1) ; 
        else if(n == 1) f[m][n] = uniquePaths(m - 1, n) ;
        else f[m][n] = uniquePaths(m - 1, n) + uniquePaths(m, n - 1);
        return f[m][n];
    }
    

Log in to reply
 

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