MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / dfs

Method dfs

java/2742-painting-the-walls.java:8–21  ·  view source on GitHub ↗
(int i, int remain, int[] cost, int[] time)

Source from the content-addressed store, hash-verified

6 return dfs(0, cost.length, cost, time);
7 }
8 private int dfs(int i, int remain, int[] cost, int[] time){
9 if(remain <= 0)
10 return 0;
11 if(i == cost.length)
12 return (int) 1e9;
13 String s = i + "," + remain;
14 if(dp.containsKey(s))
15 return dp.get(s);
16
17 int paint = cost[i] + dfs(i+1, remain-1-time[i], cost, time);
18 int skip = dfs(i+1, remain, cost, time);
19 dp.put(s, Math.min(paint, skip));
20 return dp.get(s);
21 }
22}

Callers 1

paintWallsMethod · 0.95

Calls 2

getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected