【LeetCode】Same Tree

来源:互联网 发布:php safe mode 开关 编辑:程序博客网 时间:2024/04/30 04:27


题目描述

Same Tree

 

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-循环队列,广度优先遍历

总结

对于对比的两棵树,某个结点要存在都应该存在,要不存在都应该不存在。

代码示例


推荐学习C++的资料

C++标准函数库
http://download.csdn.net/detail/chinasnowwolf/7108919
在线C++API查询
http://www.cplusplus.com/

0 0
原创粉丝点击