Skip to content

Instantly share code, notes, and snippets.

@koalicioous
Created August 13, 2023 22:18
Show Gist options
  • Save koalicioous/65bdc0c96b765de98c2fd9512275b49d to your computer and use it in GitHub Desktop.
Save koalicioous/65bdc0c96b765de98c2fd9512275b49d to your computer and use it in GitHub Desktop.
118. Pascal's Triangle
function generate(numRows: number): number[][] {
const result: number[][] = []
for (let i = 0; i < numRows; i++) {
const res = new Array(i + 1)
for (let j = 0; j <= i; j++) {
if (j === 0 || j === i) res[j] = 1
else {
res[j] = (result[i-1][j-1] + result[i-1][j])
}
}
result.push(res)
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment