Skip to content

Commit b8ce902

Browse files
committed
unique-paths solution
1 parent 23103ca commit b8ce902

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

unique-paths/krokerdile.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number} m
3+
* @param {number} n
4+
* @return {number}
5+
*/
6+
var uniquePaths = function(m, n) {
7+
const memo = {};
8+
9+
function dfs(x, y) {
10+
if (x >= m || y >= n) return 0;
11+
if (x === m - 1 && y === n - 1) return 1;
12+
13+
const key = `${x},${y}`;
14+
if (key in memo) return memo[key];
15+
16+
memo[key] = dfs(x + 1, y) + dfs(x, y + 1);
17+
return memo[key];
18+
}
19+
20+
return dfs(0, 0);
21+
};

0 commit comments

Comments
 (0)