Same Tree
来源:互联网 发布:cf出现客户端数据异常 编辑:程序博客网 时间:2024/05/16 11:08
二叉树的题目,中序遍历每个节点就行,如果不是同时走到叶子或者值不同,当然就不一样。
如下:
bool isSameTree(struct TreeNode *p, struct TreeNode *q) { if (p == NULL && q == NULL) return true; if (p == NULL || q == NULL) return false; if (p->val != q->val) return false; else return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);}
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
- rabbit MQ 3钟exchange
- ACM学习感悟——FZU2192(并查集)
- NGUI在Unity中因更改窗口区域而出现Bug的处理
- HDU 4716 Computer Graphics Problem (纯水题)
- 企业级搜索引擎Solr使用入门指南
- Same Tree
- Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程
- SSH反向连接及Autossh
- 重装系统后第一次用eclipse连接手机或者pad调试app遇到“远程主机强制关闭连接”问题
- HDU 4717 The Moving Points (三分枚举)
- Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
- Spring环境下Mybatis的配置以及工作机制
- 使用UI Automator View做UI测试
- IllegalArgumentException in class: my.models.base.BaseVo, getter method of property: id