We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c75d8e9 commit 38f7eacCopy full SHA for 38f7eac
โunique-paths/jdy8739.js
@@ -0,0 +1,35 @@
1
+var uniquePaths = function (m, n) {
2
+ const cache = new Map();
3
+
4
+ const dfs = (row, col) => {
5
+ const cacheKey = `${row}-${col}`;
6
7
+ if (cache.has(cacheKey)) {
8
+ return cache.get(cacheKey);
9
+ }
10
11
+ if (row === m - 1 && col === n - 1) {
12
+ return 1;
13
14
15
+ let count = 0;
16
17
+ if (row < m - 1) {
18
+ count += dfs(row + 1, col);
19
20
21
+ if (col < n - 1) {
22
+ count += dfs(row, col + 1);
23
24
25
+ cache.set(cacheKey, count);
26
27
+ return count;
28
29
30
+ return dfs(0, 0);
31
+};
32
33
+// ์๊ฐ๋ณต์ก๋ O(m * n)
34
+// ๊ณต๊ฐ๋ณต์ก๋ O(m * n) - 1 (matrix[m][n]์ ๋ํ ์บ์๋ ํฌํจ๋์ง ์์ผ๋ฏ๋ก)
35
0 commit comments