My JavaScript Solution


  • 1
    B
    var generate = function(numRows) {
        var res = [];
        for(var i = 0; i < numRows; i++) res[i] = (i === 0 ? [1] : i === 1 ? [1,1] : res[i-1].getNewRow());
        return res;
    };
    
    Array.prototype.getNewRow = function() {
    	var ans = [1];
    	for(var i = 0; i < this.length - 1; i++) {
    		ans.push(this[i]+this[i+1]);
    	}
    	ans.push(1);
    	return ans;
    };
    

Log in to reply
 

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