My JavaScript Solution


  • 0
    S
    /**
     * @param {number} m
     * @param {number} n
     * @return {number}
     */
    var uniquePaths = function(m, n) {
        var resMatrix = Array.apply(null, new Array(m)).map(function(){
            return new Array(n);
        });
        for(var i=0;i<m;i++){
            for(var j=0;j<n;j++){
                if(i==0 || j==0){
                    resMatrix[i][j] = 1;
                } else {
                    resMatrix[i][j] = resMatrix[i][j-1] + resMatrix[i-1][j];
                }
            }
        }
        return resMatrix[m-1][n-1];
    };
    

Log in to reply
 

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