Talentd
FleetCode

110. Balanced Binary Tree

Easy59.2% acceptance9 companies

Given a binary tree, determine if it is height-balanced.

Example 1:

Input: root = [3,9,20,null,null,15,7]
Output: true

Example 2:

Input: root = [1,2,2,3,3,null,null,4,4]
Output: false

Example 3:

Input: root = []
Output: true

Constraints:

  • The number of nodes in the tree is in the range [0, 5000].
  • -104 <= Node.val <= 104
13:11
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1# Definition for a binary tree node.
2# class TreeNode:
3# def __init__(self, val=0, left=None, right=None):
4# self.val = val
5# self.left = left
6# self.right = right
7class Solution:
8 def isBalanced(self, root: Optional[TreeNode]) -> bool:
9
Starter codePython 3Spaces: 4
Examples
Input
[3,9,20,null,null,15,7]
Input
[1,2,2,3,3,null,null,4,4]
Input
[]
Your code is saved on this device.Solution