-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsol2115.py
23 lines (22 loc) · 843 Bytes
/
sol2115.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def findAllRecipes(self, recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]:
s = set(supplies)
res = []
r_with_is = [[recipes[i], ingredients[i]] for i in range(len(recipes))]
while r_with_is:
next_r_with_is = []
for r_with_i in r_with_is:
canDo = True
for ing in r_with_i[1]:
if ing not in s:
canDo = False
next_r_with_is.append(r_with_i)
break
if canDo:
res.append(r_with_i[0])
s.add(r_with_i[0])
if len(next_r_with_is) < len(r_with_is):
r_with_is = next_r_with_is
else:
break
return res