Skip to content

Instantly share code, notes, and snippets.

@Phongtlam
Created April 6, 2017 16:44
Show Gist options
  • Save Phongtlam/829eb91fbba4939916575e5dc345e5a9 to your computer and use it in GitHub Desktop.
Save Phongtlam/829eb91fbba4939916575e5dc345e5a9 to your computer and use it in GitHub Desktop.
Pascal Solution (iterative)
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) {
var result = [];
result[0] = [1];
result[1] = [1,1];
for (var row = 2; row < n; row++){
result[row] = [1];
for (var col = 1; col <= row -1; col++){
result[row][col] = result[row-1][col] + result[row-1][col-1];
result[row].push(1);
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment