Maximum Width of Binary Tree

Given the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined as the length between the end-nodes (leftmost and rightmost non-null nodes), including the null nodes between the end-nodes in a complete binary tree extending down to that level.

Constraints

  • The number of nodes in the tree is in the range [1, 3000].
  • -100 <= Node.val <= 100
Saving… · 10 lines
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right

class Solution:
def maximumWidthOfBinaryTree(self, root: TreeNode) -> int:

Console

Click Run to execute sample tests.