leetCode--same-tree
来源:互联网 发布:印刷厂排版软件 编辑:程序博客网 时间:2024/06/05 18:34
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.
分析:很简单,先比较父节点是否相同,在比较各自的子节点即可
public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null&&q==null){ return true; } if(p==null||q==null){ return false; } return p.val==q.val&&isSameTree(p.left,q.left)&&isSameTree(p.right,q.right); }}
阅读全文
0 0
- Leetcode - Tree - Same Tree
- [leetcode][tree] Same Tree
- LeetCode: Same Tree
- LeetCode Same Tree
- [Leetcode] Same Tree
- LeetCode : Same Tree
- [LeetCode] Same Tree
- leetcode 65: Same Tree
- Leetcode 100 Same Tree
- [leetcode] Same Tree
- [LeetCode]Same Tree
- [leetcode]Same Tree
- [Leetcode]Same Tree
- Leetcode: Same Tree
- [LeetCode] Same Tree
- LeetCode-Same Tree
- [leetcode] Same Tree
- LeetCode - Same Tree
- android 一键锁屏
- [LeetCode] 206-Reverse Linked List
- linux命令的使用
- LSMW、BDC、CATT 区别
- 备忘2017年布尔教育燕十三php视频教
- leetCode--same-tree
- (3)Java环境变量设置和JDK的安装
- 微信小程序开发系列——2. 开发者工具以及开发框架简介
- Python 字符处理方法:str, repr区别
- juc 1
- C++的运算符重载
- Docker image创建之Hello world
- Stm32_调试出现 Error:Flash Download Failed-"Cortex-M3" 解决方案。
- 虚拟机Ubuntu12.04图形界面进不去解决办法