Same tree
Easytreedfsrecursion
Return true if trees p and q have the same shape and the same values in the same places.
Examples write a tree level by level, with null for a missing child: [3,9,20,null,null,15,7].
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
Constraints
- 0 ≤ number of nodes in each tree ≤ 100
- -10⁴ ≤ Node.val ≤ 10⁴
Submit checks your solution against 9 tests, including hidden ones.
// Provided by the judge: keep these definitions
class TreeNode {
constructor(val = 0, left = null, right = null) {
this.val = val
this.left = left
this.right = right
}
}
/**
* @param {TreeNode|null} p
* @param {TreeNode|null} q
* @return {bool}
*/
function isSameTree(p, q) {
}