My JavaScript Solution


  • 0
    B
    var getRow = function(rowIndex) {
        var ans = [1];
        if(rowIndex === 0) return ans;
        for(var i = 1; i <= rowIndex; i++) ans = ans.getNewRow();
        return ans;
    };
    
    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.