Last active
February 1, 2018 03:52
-
-
Save ayastreb/fcbbede3070c5584b5f92e84a6e1f5c6 to your computer and use it in GitHub Desktop.
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
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