Balanced Binary Tree
Tree
easy
Score: 20
A binary tree in which the left and right subtrees of every node differ in height by no more than 1 is known as Balanced Binary Tree.
Given a binary tree, determine if it is height-balanced.
Class TreeNode:
val (int)
left (TreeNode)
right (TreeNode)
Input Format:
First Parameter : TreeNode root
Output Format:
Return 1
if binary tree is balanced, else return 0
Example 1:
Input:
root = [2 4 6 5 9]
Output:
1
Example 2:
Input:
root = [3 11 9 5 9 null null 8]
Output:
0
Constraints:
- The number of nodes in the tree is in the range
[1, 5000]
- -10000 <=
Node.val
<= 10000 - Expected Time Complexity: O(N).
- Expected Space Complexity: O(N).