Skip to content

Instantly share code, notes, and snippets.

@samandar-boymurodov
Created June 12, 2021 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samandar-boymurodov/6eb1b13dabcd8f6e29cd2ee8689690ab to your computer and use it in GitHub Desktop.
Save samandar-boymurodov/6eb1b13dabcd8f6e29cd2ee8689690ab to your computer and use it in GitHub Desktop.
/**
* @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