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 are structurally identical, and the nodes have the same value.
Example 1
Input: p = [1,2,3], q = [1,2,3]
Output: true
Explanation: Both trees have root 1 with left child 2 and right child 3, so they are the same.
Example 2
Input: p = [1,2], q = [1,null,2]
Output: false
Explanation: In p, 2 is the left child of 1, but in q it is the right child. The shapes differ, so the trees are not the same.
Example 3
Input: p = [1,2,1], q = [1,1,2]
Output: false
Explanation: The shapes match, but the values are swapped (2 and 1 on the left, 1 and 2 on the right), so the trees differ.
Walk both trees in lockstep. At each pair of positions: both empty is a match; one empty (but not the other) or differing values is a mismatch; otherwise recurse on the left pair and the right pair together.
Run checks all cases above. Submit evaluates all test cases.