Back to course home

0% completed

# Solution: Same Tree

## Problem Statement

Given the roots of two binary trees 'p' and 'q', write a function to check if they are the same or not.

Two binary trees are considered the same if they met following two conditions:

- Both tree are structurally identical.
- Each corresponding node on both the trees have the same value.

**Example 1**:

Given the following two binary trees:

**Output**: true

**Explanation**: Both trees are structurally identical and have same values.

**Example 2**:

Given the following two binary trees:

**Output**: false

**Explanation**: Trees are structurally different.

.....

.....

.....

Like the course? Get enrolled and start learning!