1 minute read

Given two binary trees, root0 and root1, return whether their structure and values are equal.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root0
  • m ≤ 100,000 where m is the number of nodes in root1

https://binarysearch.com/problems/Twin-Trees

Examples

Example 1

Input

  • root0 =
  • root1 =

Output

  • answer = False

Explanation

These two trees are not twins since their values are different.

Example 2

Input

  • root0 =
  • root1 =

Output

  • answer = True

Explanation

These two trees have the same values and same structure.

Example 3

Input

  • root0 =
  • root1 =

Output

  • answer = False

Explanation

These two trees are not twins since their structure is different.

Solution

Leave a comment