78ms javascript solution with O(n) Time Complexity and O(1) Space Complexity


  • 0
    F
    /**
     * @param {number} m
     * @param {number} n
     * @return {number}
     */
    var uniquePaths = function(m, n) {
        var upper = 1, bottom = 1;
        m--, n--;
        for (var i = m + 1; i <= m + n; ++i)
            upper *= i;
        for (var i = 1; i <= n; ++i)
            bottom *= i;
        return upper / bottom;
    };
    

Log in to reply
 

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