Javascript solution


  • 0
    var getRow = function(rowIndex) {
    
        let retAry = [];
        for (let i = 0; i<rowIndex + 1; i++) {
            retAry[i] = [];
            for (let j = 0; j <= i; j++) {
                if (j === 0 || j === i) {
                    retAry[i].push(1);
                } else {
                    retAry[i].push(retAry[i-1][j-1] + retAry[i-1][j]); 
                }
            }
        }
       return retAry[rowIndex];
    };

Log in to reply
 

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