LeetCode Same Tree 100
2016-04-23 19:56
232 查看
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.
java练手中~~~
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/** * Definition for a binary tree node. * 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; else if(p==null && q!=null) return false; else if(p!=null && q==null) return false; else{ if(p.val == q.val){ return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); } else return false; } } }
java练手中~~~
相关文章推荐
- HBase读与写数据流程
- JAVAEE项目结构以及并发随想
- Object-C 基础学习(二)
- office2010官方下载 免费完整版
- JAVAEE项目结构以及并发随想
- MySQL错误:Can't connect to
- 学习Netty in action第一章心得
- leetcode 119.Pascal's Triangle II-杨辉三角形
- 数组足够大加零声明char*
- 第八周作业
- UESTC 1215 (思维题 旋转)
- Node.js缓冲器
- 输入一个字符串,计算字符串中子串出现的次数
- 个人工作总结5
- 修改textField的placeholder的字体颜色、大小
- Tomcat项目部署方式
- 关于用ObjectInputStream遍历读取文件中的对象,如何判断到达文件末尾
- 数据挖掘工作指南(1)
- pickle序列化
- iOS 拨打电话三种方式总结