← All problems

Same Tree

easy

Given the roots of two binary trees p and q, return true if they are structurally identical and every corresponding node holds the same value.

Example

Input: p = [1, 2, 3], q = [1, 2, 3]
Output: true

Input: p = [1, 2], q = [1, null, 2]
Output: false
Loading...