same-tree
来源:互联网 发布:mac os x系统迅雷下载 编辑:程序博客网 时间:2024/05/06 15:52
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.
/** * 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){ if(p.val == q.val){ return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); }else{ return false; } }else{ if(p == q){ return true; }else{ return false; } } }}
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
- HDU 1556Color the ball
- 使用redis缓存网站首页
- Java微信公众平台开发(三)——接收消息的分类及实体的创建
- windows实现端口映射
- mock server 学习笔记
- same-tree
- 史上最全的CSS hack方式一览
- Java微信公众平台开发(四)——回复消息的分类及实体的创建
- 字符串第一次包含目标字符集合元素的最小范围
- 【火车进出站 - 递归全排列 + 遍历】
- MySQL语句大全
- 递归二 - 汉诺塔
- unity 摄像头跟踪目标
- 全屏滑动返回手势sunnyxx