[Microsoft] Identical Binary Tree
来源:互联网 发布:2015年网络零售总额 编辑:程序博客网 时间:2024/06/05 04:11
Check if two binary trees are identical. Identical means the two binary trees have the same structure and every identical position has the same value.
Example
1 1 / \ / \ 2 2 and 2 2 / /4 4
are identical.
1 1 / \ / \ 2 3 and 2 3 / \4 4
are not identical.
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */public class Solution { /** * @param a, b, the root of binary trees. * @return true if they are identical, or false. */ public boolean isIdentical(TreeNode a, TreeNode b) { if(a==null && b==null){ return true; } if(a==null || b==null){ return false; } if(a.val==b.val){ return isIdentical(a.left, b.left) && isIdentical(a.right, b.right); } return false; }}
阅读全文
0 0
- [Microsoft] Identical Binary Tree
- Identical Binary Tree
- lintcode:Identical Binary Tree
- LeetCode Identical Binary Tree 相同二叉树
- 【LeetCode】Identical Binary Tree等价二叉树
- 469.Identical Binary Tree-等价二叉树(容易题)
- check whether two binary trees are identical
- Binary tree
- Binary Tree
- Binary Tree
- Binary Tree
- Binary Tree
- Binary Tree
- Binary Tree
- binary tree
- Binary Tree
- Binary Tree
- Binary Tree
- android之服务service远程服务
- webpack+vue 实现多页面开发
- 05.15 三剑客之老四find命令详解
- dva -react TypeError: root.findRouters(...).getRouterInfo is not a function
- 关于在Windows10 Eclipse 配置Dos(cmd)窗口
- [Microsoft] Identical Binary Tree
- 简单粒子群优化算法的函数寻优
- 基于类实现的简易计算器
- python简单爬虫开发(urllib2、requests + BeautifulSoup)
- Makefile小细节
- STL的list成员函数
- css3之filter函数
- 39/40. Combination Sum (两题)
- 查找单链表的倒数第k个节点,要求只能遍历一次链表