leetcode 100. Same Tree

来源:互联网 发布:淘宝主图尺寸750 编辑:程序博客网 时间:2024/06/16 17:27
题目:

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.

判断两棵二叉树是否相等,即结构相同,且对应的节点具有相同的值


思路:由树的前序、中序和后序遍历,想到用递归的方法,先判断根节点是否相同,再依次判断左子树和右子树是否相同。


代码AC:


0 0
原创粉丝点击