Skip to content

Commit 062eb69

Browse files
authored
Update solution.ts
1 parent b118e52 commit 062eb69

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

src/main/kotlin/g2601_2700/s2630_memoize_ii/solution.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,22 @@ function memoize(fn: Fn): Fn {
1313
currentCache = new Map()
1414
cache.set(args.length, currentCache)
1515
}
16-
1716
for (let i = 0, len = args.length; i <= len; i++) {
1817
const arg = args[i]
1918
const isEnd = i >= len - 1
20-
2119
if (currentCache.has(arg)) {
2220
if (isEnd) {
2321
return currentCache.get(arg)
2422
} else {
2523
currentCache = currentCache.get(arg)
2624
}
27-
} else {
28-
if (isEnd) {
29-
break
30-
} else {
31-
const newSubCache = new Map()
32-
33-
currentCache.set(arg, newSubCache)
34-
currentCache = newSubCache
35-
}
25+
} else if (!isEnd) {
26+
const newSubCache = new Map()
27+
currentCache.set(arg, newSubCache)
28+
currentCache = newSubCache
3629
}
3730
}
38-
39-
let value = fn.apply(null, args)
40-
31+
let value = fn.apply( ...args)
4132
currentCache.set(args[args.length - 1], value)
4233
return value
4334
}

0 commit comments

Comments
 (0)