Skip to content

Instantly share code, notes, and snippets.

@ayastreb
Last active February 1, 2018 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayastreb/fcbbede3070c5584b5f92e84a6e1f5c6 to your computer and use it in GitHub Desktop.
Save ayastreb/fcbbede3070c5584b5f92e84a6e1f5c6 to your computer and use it in GitHub Desktop.
function numOfPathsToDest(n) {
if (n === 1) return 1;
let lastRow = new Array(n).fill(1);
let currentRow = [];
for (let row = 1; row < n; row++) {
for (let col = row; col < n; col++) {
const lastCol = col > row ? currentRow[col - 1] : 0;
currentRow[col] = lastRow[col] + lastCol;
}
lastRow = currentRow;
}
return currentRow[n - 1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment