3 Liner Pure Math Method C++ O(m) time, O(1) space


  • 1
    F
    struct Solution {
        int uniquePaths(int m, int n) {
            double product = 1;
            for (int i = 0; i < m - 1; ++i)
                product *= (double)(m + n - i - 2) / (m - 1 - i);
            return round(product);
        }
    };

Log in to reply
 

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