Given the root nodes of two binary trees, a and b, determine whether the two trees are equal.
a
b
Two binary trees are considered equal if they have the same structure and the corresponding nodes in both trees have the same values.
The binary tree is represented by a collection of TreeNodes, where each node has optional left and right child nodes, which are also TreeNodes.
TreeNode
left
right
A TreeNode has the following interface:
interface TreeNode { val: number; left: TreeNode | null; right: TreeNode | null;}
a: TreeNode
b: TreeNode
Input: a = [1,2], b = [1,null,2]Output: falseExplanation: The trees differ in the structure.
Input: a = [3,null,7], b = [3,5,7]Output: falseExplanation: The first tree has a null left child, while the second tree has a left child with value 5.
Input: a = [65,null,17], b = [65,null,17]Output: trueExplanation: Both trees have the same structure and node values.
TreeNode.val
console.log()