Leetcode 100 Same Tree
2015-06-19 19:36
375 查看
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.
递归:如果root均为null则全等,如果root非null,则子树全等+root值相同=>两树全等。
循环:expected to be added...
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
递归:如果root均为null则全等,如果root非null,则子树全等+root值相同=>两树全等。
def is_same_tree(p, q) return true if not p and not q return is_same_tree(p.left,q.left) && is_same_tree(p.right,q.right) if p and q and p.val == q.val false end
循环:expected to be added...
相关文章推荐
- Linux下Tcl和expect 的安装
- 美女程序员是如何将QQ转换成题目中那串数字的--读博文《找女神要QQ号码》
- OC8_NSData
- nodejs ajax 请求
- sql 语句随机时间存储过程
- html css float 的使用说明
- Nginx反向代理与负载均衡
- 机器学习的数学基础(1)--Dirichlet分布
- Kotlin教程学习-控制流
- PL/SQL 异常处理程序
- 支持向量机的优缺点
- 字符串的格式化
- windows下perl脚本中安装使用parallel:ForkManager
- Gradle使用讲解
- 二维卷积c代码
- OC7_目录操作
- 微信屏蔽网页跳转到app store的解决办法
- 【Linux】linux常用基本命令
- MyBatis学习门户网站(一)
- python函数式编程――偏函数