【题目描述】
Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
检查两棵二叉树是否等价。等价的意思是说,首先两棵二叉树必须拥有相同的结构,并且每个对应位置上的节点上的数都相等。
【题目链接】
www.lintcode.com/en/problem/identical-binary-tree/
【题目解析】
对两棵树同时使用递归进行前序遍历,并对同一位置的节点进行判断,如有不相等则不是等价二叉树。
【参考答案】
网友评论