Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f83d37c

Browse files
Create Solution.py
1 parent 96a46d8 commit f83d37c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎Ones and Zeroes/Solution.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
3+
count = [Counter(s) for s in strs]
4+
@lru_cache(None)
5+
6+
def func(i, a, b):
7+
if a > m or b > n:
8+
return -1
9+
if i == len(strs):
10+
return 0
11+
x = func(i + 1, a + count[i]['0'], b + count[i]['1'])
12+
if x != -1:
13+
return max(1 + x, func(i + 1, a, b))
14+
return func(i + 1, a, b)
15+
return func(0, 0, 0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /