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.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/ class Solution { public:bool isSameTree(TreeNode* p, TreeNode* q) {if (p == NULL && q == NULL) return true;if (p == NULL && q != NULL) return false;if (p != NULL && q == NULL) return false;if (p->val == q->val) {bool x = isSameTree(p->left, q->left);bool y = isSameTree(p->right, q->right);return x&&y;}return false;} };
转载于:https://www.cnblogs.com/pk28/p/7218111.html
100. Same Tree相关推荐
- LeetCode 100. Same Tree
LeetCode 100. Same Tree Solution1: 这种弱智题提交这么多次... /*** Definition for a binary tree node.* struct Tr ...
- [Leetcode]100. Same Tree -David_Lin
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- [LeetCode] NO. 100 Same Tree
[题目] Given two binary trees, write a function to check if they are equal or not. Two binary trees ar ...
- 100. Same Tree同样的树
[抄题]: Given two binary trees, write a function to check if they are the same or not. Two binary tree ...
- Leet Code OJ 100. Same Tree [Difficulty: Easy]
题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...
- 32/100. Binary Tree Inorder Traversal
中序遍历二叉树. 递归法: # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x) ...
- 16/100. Symmetric Tree
给定一个二叉树,看它是不是"镜像树"(瞎起的). 递归.从上往下,分别判断左右子树的根节点值是否相等,相等则继续往下递归,不等则返回False. # Definition for ...
- [LeetCode]: 100: Same Tree
题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...
- [leetcode]100.Same Tree
题目 Given two binary trees, write a function to check if they are the same or not. Two binary trees a ...
最新文章
- 2015/Province_C_C++_C/8/饮料换购
- Topk 问题详解及代码和数据分析
- 用aria2c下迅雷离线资源
- [转载]使用命名管道实现进程间通信
- MyBatis + MVC 获取 UI 参数的几种方法(二)
- lintcode 中等题:Single number III 落单的数III
- JAVA企业级应用服务器之TOMCAT实战
- python 机器学习——从感知机算法到各种最优化方法的应用(python)
- [Serializable]C#中的对象序列化
- PLC项目增频减频部分流程图(修改版)
- java 如何去掉http debug日志_Java高手如何搭建高效易用的日志系统
- robotstudio工作站建立
- pv 、uv、ip、vv、cv分别是什么
- java 锟斤 解决乱码_java eclipse 开发中文乱码锟斤拷小锟斤拷锟
- javaWeb(b站狂神说)
- R语言入门第一集 R语言、RTools、RStudio的简介、安装与使用
- android网络传输唤醒系统,Android手机唤醒群晖NAS系统
- 转载:关于Vivado综合选项——Out of context per IP和Gobal
- c# UTC时间和本地时间转换(北京时间)
- ADI DSP的寄存器详细说明在哪里?
热门文章
- css规则可以放在云上,CSS中!important规则的使用方法
- c语言调用go函数,C中调用go中的回调函数
- php 实例 规范,PHP开发规范实例详解
- 清除浏览器缓存之后为什么还是显示旧的html页面_Web缓存控制策略详解
- java changestr,java change
- java s1_转!!Java 基础面试题的剖析: short s1=1;s1 = s1 +1 报错? s1+=1 呢
- 一些图形学中的数学应用
- 人工神经网络——笔记摘抄2
- 机器学习两种距离——欧式距离和马氏距离
- Ubuntu中python调用SimpleITK来显示图像