Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number} numRows
- * @return {number[][]}
- */
- var generate = function(numRows) {
- var result = [[1]];
- if (numRows = 1) {
- return result = result;
- }
- for (var row = 1; row < n; row++) {
- for (var col = 1; col <= row; col++) {
- result[row][col] = result[row -1][col] + result [row - 1][col -1];
- }
- }
- return result;
- };
- // input: number
- // output: array
- // constraints: none
- // edge cases: none
- // enter a number of rows and output an array with subarrays with values respective to pascals triangle
- // base case: when numRows equals 1, return output
Add Comment
Please, Sign In to add comment