Last active
August 31, 2017 17:04
-
-
Save kennyxcao/3d67481f8d864369a810bea397b1a0bd to your computer and use it in GitHub Desktop.
PascalTriangle LeetCode Solution
This file contains hidden or 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 = []; | |
| for (var i = 0; i < numRows; i++) { | |
| var row = []; | |
| if (i === 0) { | |
| row.push(1); | |
| result.push(row); | |
| } else { | |
| var j = 0; | |
| while(j <= i) { | |
| if (j === 0) { | |
| row.push(1); | |
| } else if (j === i) { | |
| row.push(1); | |
| result.push(row); | |
| } else { | |
| var value = result[i - 1][j - 1] + result[i - 1][j]; | |
| row.push(value); | |
| } | |
| j++; | |
| } | |
| } | |
| } | |
| return result; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment