Dodomeki
Sign in

30. Balanced Tree

Easy

Return true if, at every node, the heights of the left and right subtrees differ by at most one. An empty tree is balanced.

Example 1
Input: raiz = [6, 3, 9, 1, 4]
Output: true
Example 2
Input: raiz = [6, 3, null, 2, null, 1]
Output: false
Constraints
  • 0 <= quantidade de nós <= 10^4
TreesDFS
Caso 1
raiz =
[6,3,9,1,4]
Expected =
true
Caso 2
raiz =
[6,3,null,2,null,1]
Expected =
false

Run checks these 2 cases. Submit runs all 6, including hidden ones.