Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created July 10, 2020 23:04
Show Gist options
  • Save RP-3/4c799c680f56532f76afe46d381bb5d9 to your computer and use it in GitHub Desktop.
Save RP-3/4c799c680f56532f76afe46d381bb5d9 to your computer and use it in GitHub Desktop.
/**
* @param {number} rowIndex
* @return {number[]}
*/
var getRow = function(index) {
if(index === 0) return [1];
let [result, next] = [[1], []];
for(let row=1; row<=index; row++){
for(let j=0; j<=result.length; j++){
const prev = result[j-1] || 0;
const curr = result[j] || 0;
next.push(prev + curr);
}
result = next;
next = [];
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment