# 1161. Maximum Level Sum of a Binary Tree https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ ###### tags: `Python`,`Leetcode` ## Code! ``` python= from collections import deque class Solution: def maxLevelSum(self, root: Optional[TreeNode]) -> int: maxi, level, maxlevel = -float('inf'), 0, 0 q = deque() q.append(root) while q : level += 1 summation = 0 for i in range(len(q)): node = q.popleft() summation += node.val if node.left: q.append(node.left) if node.right: q.append(node.right) if maxi < summation: maxi, maxlevel = summation, level return maxlevel ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up