MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Method dfs

python/0474-ones-and-zeroes.py:18–30  ·  view source on GitHub ↗
(i, m, n)

Source from the content-addressed store, hash-verified

16 dp = {}
17
18 def dfs(i, m, n):
19 if i == len(strs):
20 return 0
21 if (i, m, n) in dp:
22 return dp[(i, m, n)]
23
24 mCnt, nCnt = strs[i].count("0"), strs[i].count("1")
25 dp[(i, m, n)] = dfs(i + 1, m, n)
26 if mCnt <= m and nCnt <= n:
27 dp[(i, m, n)] = max(
28 dp[(i, m, n)],
29 1 + dfs(i + 1, m - mCnt, n - nCnt))
30 return dp[(i, m, n)]
31
32 return dfs(0, m, n)

Callers

nothing calls this directly

Calls 3

dfsFunction · 0.50
maxFunction · 0.50
countMethod · 0.45

Tested by

no test coverage detected