[Python3] Maximum Level Sum


#1

import queue
class Solution:
# @param A : root node of tree
# @return an integer
def solve(self, A):
if not A:
return None

    q = queue.Queue()
    q.put(A)
    res=[]
    
    while not q.empty():
        a=[]
        size = q.qsize()
        
        while size!=0:
            curr = q.get()
            a.append(curr.val)
            
            if curr.left:
                q.put(curr.left)
                
            if curr.right:
                q.put(curr.right)
                
            size-=1
        
        if len(a)!=0:
            res.append(sum(a))
    
    return max(res)