Created
June 12, 2021 19:41
-
-
Save samandar-boymurodov/6eb1b13dabcd8f6e29cd2ee8689690ab to your computer and use it in GitHub Desktop.
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) { | |
const p = [] | |
p[0] = [1] | |
p[1] = [1, 1] | |
if (numRows === 1) return p[0] | |
for (let i = 2; i <= numRows - 1; i++) { | |
p[i] = [1] | |
for (let j = 0; j <= p[i-1].length - 2; j++) { | |
p[i].push(p[i-1][j] + p[i-1][j+1]) | |
} | |
p[i].push(1) | |
} | |
return p | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment