Created
April 6, 2017 16:44
-
-
Save Phongtlam/829eb91fbba4939916575e5dc345e5a9 to your computer and use it in GitHub Desktop.
Pascal Solution (iterative)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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