less than 1 minute read

Given a binary tree root, return whether all leaves are at the same level.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root

https://binarysearch.com/problems/Leaves-in-Same-Level

Examples

Example 1

Input

  • root =

Output

  • answer = False

Explanation

Leaves 2 and 4 are on different levels.

Example 2

Input

  • root =

Output

  • answer = True

Explanation

Leaves 2 and 0 are on the same level.

Solution

Leave a comment