#100
Same Tree
pupil · 310 · lc easy +21 · verified · 66.7% accepted · 12,815 likes · top 72%
Description
Given roots p and q of two binary trees, return true if the trees are identical — structurally the same with equal values at every corresponding node.
Example 1:
Input: p = [1,2,3], q = [1,2,3]
Output: true
Example 2:
Input: p = [1,2], q = [1,null,2]
Output: false
Example 3:
Input: p = [1,2,1], q = [1,1,2]
Output: false
Code
1
2
3
4
5
6
7
8
9