Maximum Candies You Can Get from
2020-07-03 本文已影响0人
斯文攸归
class Solution:
def maxCandies(self, status: List[int], candies: List[int], keys: List[List[int]], containedBoxes: List[List[int]], initialBoxes: List[int]) -> int:
if len(initialBoxes) == 0:
return 0
if 1 not in status:
return 0
new_Boxes = []
num_candies = 0
while True:
flag = False
for b in initialBoxes:
if status[b] == 1:
flag = True
num_candies += candies[b]
new_Boxes += containedBoxes[b]
if len(keys[b]) != 0:
for j in keys[b]:
status[j] = 1
initialBoxes.remove(b)
initialBoxes += new_Boxes
new_Boxes = []
if not flag:
break
return num_candies