forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1298.py
More file actions
19 lines (18 loc) · 676 Bytes
/
Copy path1298.py
File metadata and controls
19 lines (18 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution:
def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], initialBoxes: List[int]) -> int:
q, res = initialBoxes, 0
while q:
q_len, changed = len(q), False
for _ in range(q_len):
b = q.pop(0)
if status[b]:
changed = True
res += candies[b]
q += containedBoxes[b]
for i in keys[b]:
status[i] = 1
else:
q.append(b)
if not changed:
return res
return res