Created
December 4, 2020 19:33
-
-
Save iJustErikk/d9363b61fb89706cfe73f4338b73675d to your computer and use it in GitHub Desktop.
This file contains 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
const gridTraveler = (m, n, memo = new Map()) => { | |
const key = `${m},${n}`; | |
if (memo.has(key)) return memo.get(key); | |
if (m === 0 || n === 0) return 0; | |
if (m === 1 && n === 1) return 1; | |
memo.set(key, gridTraveler(m - 1, n, memo) + gridTraveler(m, n - 1, memo)); | |
return memo.get(key); | |
}; | |
console.log(gridTraveler(20, 20)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment