判断两棵树是否相等 leecode
2014-06-29 02:03
260 查看
很简单 提交代码 https://oj.leetcode.com/problems/same-tree/[/code] iven 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./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null&&q==null) return true; if(p==null||q==null) return false; if(p.val==q.val) { return isSameTree(q.left,p.left)&&isSameTree(q.right,p.right); } else { return false; } } }
相关文章推荐
- 判断两棵树是否相等
- 用递归方法判断两棵树是否相等
- 判断两棵树是否相等
- (树)判断两棵树是否相等
- Same Tree 判断两棵树是否相等
- 二叉树(二) 求二叉树高度,根据先序和中序构建二叉树,判断二叉树是否是完全二叉树,判断两棵树是否相等
- 树---判断两棵树是否相等
- 判断两棵树是否相等
- 代码实现判断两棵树是否相等
- java实现二叉树查找,统计结点个数,统计树的深度及判断两棵树是否相等
- 判断两棵树是否相等
- LeeCode 判断两个二叉树是否相等
- 判断两棵树是否相等
- 百度面试题:判断两棵树是否相等
- 判断两棵树是否相等
- Javascript判断对象是否相等实现代码
- 1203 判断浮点数是否相等
- 不要使用equals方法对AtomicXXX进行是否相等的判断
- android、Java下判断两个String是否相等 、EditText输入是否为空,
- 【codeforces】-- Life Without Zeros(两个数先加后消去包含的零和先消后加判断是否相等 )