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
4
and5
, 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
11
is at depth3
and leaf node16
is at depth4
. So, both leaf nodes are at different depth.
Example 3:
- Input: root =
[10, 8, 15, 17, null, 12]
- Expected Output:
true
- Justification: The leaves are nodes
17
, and12
, and all are located at the same level (level 3).
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself