[LeetCode] NO. 100 Same Tree
[题目]
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 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(null == p && null == q) return true;if(null != p && null != q){return (p.val == q.val && isSameTree(p.left,q.left) && isSameTree(p.right,q.right));}else{return false;}} }
转载于:https://www.cnblogs.com/zzchit/p/5778166.html
[LeetCode] NO. 100 Same Tree相关推荐
- LeetCode 100. Same Tree
LeetCode 100. Same Tree Solution1: 这种弱智题提交这么多次... /*** Definition for a binary tree node.* struct Tr ...
- LeetCode Top 100 Liked 点赞最高的 100 道算法题
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:刷题顺序,刷题路径,好题,top100,怎么刷题,Leet ...
- LeetCode: 106. Construct Binary Tree from Inorder and Postorder Traversal
题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume ...
- LeetCode 110 Balanced Binary Tree 平衡二叉树
LeetCode 110 Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this ...
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++...
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++ Given preo ...
- LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal Solution1:我的答案 仿照105题写的答案 / ...
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 本博客转载自:http://www.cnblogs.co ...
- LeetCode 110. Balanced Binary Tree
LeetCode 110. Balanced Binary Tree 本博客参考自:http://www.cnblogs.com/grandyang/p/4045660.html Solution1: ...
- LeetCode: 173. Binary Search Tree Iterator
LeetCode: 173. Binary Search Tree Iterator 题目描述 Implement an iterator over a binary search tree (BST ...
最新文章
- fedora12安装小企鹅输入法
- RxJava 参考文档
- nginx 1.4.3能直接升到1.8.1吗
- 沈梦辰回应闲鱼卖假货事件:负责到底 不做一锤子买卖
- Javabean的理解(通过javabean的部分程序)
- IJCAI 2019 | 为推荐系统生成高质量的文本解释:基于互注意力机制的多任务学习模型...
- flex 常用正则验证举例
- php生成迷宫图片,PHP实现基于回溯法求解迷宫问题的方法详解
- 计算机数据及报告备份记录表,数据处理-泉州市第六次全国人口普查-专题专栏-泉州统计信息网...
- python词云图背景_python词云图之WordCloud
- WindwosServer系统一些设置【网卡驱动修复】【安装UWP应用】【服务器管理取消开机自启动】
- 手机WIFI传文件到局域网服务器,局域网内手机和电脑怎么实现无线传输文件?
- 使用TextPaint实现自由加粗字体:BoldTextView,支持中粗
- Python人工智能完整学习路线
- 谭浩强C语言学习day1
- VS 2019 C++ 如何在非控制台程序中打开控制台
- 远程ARM设备Xavier方法——ZeroTier+nomachine
- Web兼容性测试的要点
- coding期间遇到的bug记录
- ESP32学习笔记(34)——BLE一主多从连接