美文网首页
Maximum Candies You Can Get from

Maximum Candies You Can Get from

作者: 斯文攸归 | 来源:发表于2020-07-03 16:12 被阅读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
    

    相关文章

      网友评论

          本文标题:Maximum Candies You Can Get from

          本文链接:https://www.haomeiwen.com/subject/uewsqktx.html