js solution.


  • 0
    N
    var generate = function(numRows) {
        if(numRows == 0)return [];
        if(numRows == 1)return [[1]];
        if(numRows == 2)return [[1], [1, 1]];
        var ret = [[1], [1, 1]];
        for(var i = 2; i < numRows; i++){
            ret[i] = new Array();
            ret[i].push(1);
            for(var j = 1; j < i; j++){
                ret[i].push(ret[i - 1][j - 1] + ret[i - 1][j]);
            }
            ret[i].push(1);
        }
        return ret;
    };
    

Log in to reply
 

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