same-tree
来源:互联网 发布:火鸟中文移动编程 编辑:程序博客网 时间:2024/05/22 11:45
题目:
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.
程序:
class Solution {public: bool isSameTree(TreeNode *p, TreeNode *q) { if(p == NULL && q == NULL) return true; else if(p == NULL || q == NULL) return false; else if(p->val == q->val) return isSameTree(p->left,q->left) && isSameTree(p->right,q->right); return false; }};
阅读全文
0 0
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- Same Tree
- TP5中文名上传乱码,解决办法
- html评论中星星点亮的效果jquery代码
- C++STL系列 结构体运算符重载及优先队列的使用
- 设计模式-模板方法模式
- Shell脚本编程-分支与循环
- same-tree
- Apache Camel
- 75
- Win10:电脑共享WIFI
- NGUI 3.5教程(二)Label 标签 (Hello world)、多行文本
- 在Ubuntu(Linux)系统中安装一些软件以及工具
- SNMP开发过程中的一些积累
- 探索数据库的事务隔离级别
- 326. Power of Three