Javascript solution


  • 0
    N
    /**
     * @param {number} numRows
     * @return {number[][]}
     */
    var generate = function(numRows) {
        var numArr = [];
        
        for(var i = 0; i < numRows; i++){
            var e = [];
            for(var j = 0;j <= i;j++){
                if(i == j){
                    e.push(1);
                }
                else{
                    e.push(j == 0 ? numArr[i-1][j] : numArr[i-1][j-1]+numArr[i-1][j]);
                }
                
            }
            numArr.push(e);
        }
       
        return numArr;
    };
    

Log in to reply
 

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