My C++ solution, calculate directly


  • 0
    F
    int uniquePaths(int m, int n) {
            // C(n + m - 2, m - 1)
            if (m < n) swap(m, n);
            long long t = 1;
            for (int i = 0; i < n - 1; i++) {
                t = t * (i + m) / (i + 1);
            }
            return (int) t;
        }
    

Log in to reply
 

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