[LC] 100. Same Tree
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same 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; }
* }
*/
class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null && q == null) {
return true;
} else if (p == null && q != null || p != null && q == null) {
return false;
} else if (p.val != q.val) {
return false;
}
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}
}
[LC] 100. Same Tree的更多相关文章
- 100. Same Tree(C++)
100. Same Tree Given two binary trees, write a function to check if they are equal or not. Two binar ...
- LeetCode Javascript实现 100. Same Tree 171. Excel Sheet Column Number
100. Same Tree /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; ...
- 100.Same Tree(E)
100. same tree 100. Same Tree Given two binary trees, write a function to check if they are the same ...
- <LeetCode OJ> 100. Same Tree
100. Same Tree Total Accepted: 100129 Total Submissions: 236623 Difficulty: Easy Given two binary tr ...
- LeetCode 100. Same Tree (判断树是否完全相同)
100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...
- leetcode 100. Same Tree、101. Symmetric Tree
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...
- 100. Same Tree同样的树
[抄题]: Given two binary trees, write a function to check if they are the same or not. Two binary tree ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- LeetCode之100. Same Tree
------------------------------------------ 递归比较即可 AC代码: /** * Definition for a binary tree node. * p ...
随机推荐
- 京东云数据库RDS SQL Server高可用概述
数据库的高可用是指在硬件.软件故障发生时,可以将业务从发生故障的数据库节点迁移至备用节点.本文主要讲述SQL Server高可用方案,以及京东云RDS数据库的高可用实现. 一.高可用解决方案总览 1. ...
- linux配置词典goldendict
在mint 18下使用通过, ubuntu 类似. 方法: 通过软件中心安装goldendict,或者 sudo apt install goldendict 通过网页抓取程序, 见附录 下载朗道词典 ...
- linux的/dev内容介绍
http://www.cnblogs.com/lidabo/p/4505360.html 这个结合那个linux的终端介绍 https://zhidao.baidu.com/question/1742 ...
- python编程:从入门到实践----第四章>操作列表
一.遍历整个列表 1-1.假设有一个魔术师名单,需要将其中每个魔术师的名字都打印出来. # 用for循环来打印魔术师名单中的名字 magicians=['alice','david','carolin ...
- 基于serverless快速部署前端项目到腾讯云
腾讯云 COS 组件,可以快速部署静态网站页面到对象存储 COS 中,并生成域名供访问. 安装 首先要安装 serverless 组件 npm install -g serverless 在项目的根目 ...
- [CTSC2008]祭祀(二分图匹配)
没有SPJ时显然是不需要输出方案的.不需要输出方案很好做,先把边扩展(因为会往下流),然后求最大独立集,最大独立集=n-最小点覆盖,因为其是最大独立集的补集.如何求最小点覆盖呢?毕竟我写过最大权闭合子 ...
- Python笔记_第一篇_面向过程_第一部分_7.文件的操作(.txt)
在平时,我们不光要对程序内的代码进行输入和输出的操作,还要对程序外的文件进行和语言之间的交换.操作和运算.在基础部分,先讲解对于外部的.txt文件的操作. 第一部分 基本内容讲解 1. 什么是文件 ...
- 5.windows-oracle实战第五课 --事务、函数
什么是事务 事务用于保证数据的一致性,它由一组相关的dml语句组成,该组的dml语句要么全部成功,要么全部失败. 事务和锁 当执行一个事务dml的时候,oracle会被作用 ...
- 20199324《Linux内核原理与分析》第十一周作业
SET-UID程序漏洞实验 一.实验简介 Set-UID 是 Unix 系统中的一个重要的安全机制.当一个 Set-UID 程序运行的时候,它被假设为具有拥有者的权限.例如,如果程序的拥有者是root ...
- 理解python的可变参数
以 str.format(*args,**kwargs) 为例. "type1:{},{},{},{}_type2:{a},{b},{c},{d}".format('a',2,*[ ...