Same Tree
Easy
LC #100
dfsrecursionNot attempted yet
Given the roots p and q of two binary trees, return
True if they are identical (same shape, and every
pair of matching nodes holds the same value), otherwise
False.
Example 1
Input: p = [1, 2, 3], q = [1, 2, 3]
Output: True
Example 2
Input: p = [1, 2], q = [1, None, 2]
Output: False
Same values, different shape.
Example 3
Input: p = [1, 2, 1], q = [1, 1, 2]
Output: False
Constraints
- 0 ≤ nodes in each tree ≤ 2 · 10^4
- -10^5 ≤ Node.val ≤ 10^5