67_leetcode_Same Tree
来源:互联网 发布:杭州哪里程序员多 编辑:程序博客网 时间:2024/05/01 11:00
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:采用递归的方法,注意递归结束的情况
bool isSameTree(TreeNode *p, TreeNode *q) { if((p == NULL && q != NULL) || (p != NULL && q == NULL)) { return false; } else if(p == NULL && q == NULL) { return true; } else { if(p->val == q->val) { return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); } else { return false; } } }
0 0
- 67_leetcode_Same Tree
- 67:Symmetric Tree
- Tree
- tree
- tree
- TREE
- Tree
- Tree
- tree
- tree
- tree
- tree
- tree
- tree
- Tree
- Tree
- tree
- TREE
- 日历日程控件Planner .NET详细介绍
- 如何判断硬盘出现故障? 硬盘出现故障的5种情况
- nmap端口扫描命令
- FFmpeg学习资源
- centos6.5下安装php+mysql+apache并整合的具体流程
- 67_leetcode_Same Tree
- Android4.2蓝牙基础架构学习
- javascript常用功能
- caffe源码分析--softmax_layer.cpp
- Spark Standalone模式应用程序开发
- 电子商务网站支付功能开发总结
- Codility3 PermMissingElem
- 学习linux/unix编程方法的建议学习路径
- java MD5加密