Skip to content

Commit dab2ec3

Browse files
authored
Create 2742-painting-the-walls.js
1 parent 12e56cc commit dab2ec3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2742-painting-the-walls.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} cost
3+
* @param {number[]} time
4+
* @return {number}
5+
*/
6+
const paintWalls = function(cost, time) {
7+
const n = cost.length
8+
const cache = {}
9+
10+
return dfs(n - 1, 0)
11+
12+
function dfs(i, j) {
13+
if(j > i) return 0
14+
if(i < 0) return Number.MAX_SAFE_INTEGER
15+
const k = `${i},${j}`
16+
if(cache[k] != null) return cache[k]
17+
18+
const res = Math.min(dfs(i - 1, j + time[i]) + cost[i], dfs(i - 1, j - 1))
19+
cache[k] = res
20+
return res
21+
}
22+
};

0 commit comments

Comments
 (0)