Back to course home
0% completed
Vote For New Content
Check if all leaves are at same level (medium)
Problem Statement
Given a root of the binary tree, return true if all the leaf nodes of this tree exist at the same depth. Otherwise, return false.
Examples
Example 1:
- Input: root =
[1, 2, 3, 4, null, null, 5]
- Expected Output:
true - Justification: The leaves are nodes
4and5, and they are both at the same level (level 3).
Example 2:
- Input: root =
[12, 20, 13, null, 10, 11, null, 16]
- Expected Output:
false - Justification: The leaf node
11is at depth3and leaf node16is at depth4
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page