The code is wrong? in my local compiler it runs right,but int he OJ,it is wrong only for test case [100,1]


  • 0
    T

    class Solution {
    public:
    int uniquePaths(int m, int n) {
    int N = n + m - 2;// how much steps we need to do
    int k = m - 1; // number of steps that need to go down
    double res = 1;
    // here we calculate the total possible path number
    // Combination(N, k) = Combination(N, N - k)
    for (int i = 1; i <= k; i++)
    res = res * (N - i + 1) / i;
    return (int)res;
    }
    };

    if I change the res = res * (N - i + 1) / i to res = res * (N - k + i) / i then the code got accepted


Log in to reply
 

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