Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
1 2 3 4 5 |
if let p = p, let q = q { return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right) } else { return p == nil && q == nil } |
❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼