Created
August 13, 2023 22:18
-
-
Save koalicioous/65bdc0c96b765de98c2fd9512275b49d to your computer and use it in GitHub Desktop.
118. Pascal's Triangle
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
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