【easy】100. Same Tree
判断两棵二叉树是否相等
/**
* 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)||(q==NULL&&p!=NULL)) return false;
if (p==NULL && q==NULL) return true; if (p->val != q->val) return false;
else return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
/*
if (p->left != NULL && q->left != NULL){
if (p->left->val != q->left->val) return false;
isSameTree(p->left,q->left);
}
if (p->right != NULL && q->right != NULL){
if (p->right->val != q->right->val) return false;
isSameTree(p->right,q->right);
}
//一个大错特错的递归…………
*/
//return true;
}
};
【easy】100. Same Tree的更多相关文章
- 【LeetCode】100. Same Tree 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- 【LeetCode】100 - Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- 【easy】257. Binary Tree Paths 二叉树找到所有路径
http://blog.csdn.net/crazy1235/article/details/51474128 花样做二叉树的题……居然还是不会么…… /** * Definition for a b ...
- 【easy】107. Binary Tree Level Order Traversal II 按层输出二叉树
按层输出二叉树,广度优先. 3 / \ 9 20 / \ 15 7 [ [15,7], [9,20], [3] ] /** * Definition for a binary tree node. * ...
- 【easy】101. Symmetric Tree
判断一棵二叉树是否对称 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left ...
- 【LeetCode】100. Same Tree (2 solutions)
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 【Leetcode】【Easy】Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- 606. Construct String from Binary Tree 【easy】
606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...
- 【数据结构】B-Tree, B+Tree, B*树介绍 转
[数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...
随机推荐
- centos 7修改时区
在线上环境遇到时间差八小时,怀疑是时区的原因: 然后再linux上运行: date 发现输出的是UTC时间,时间与现在差八个小时 然后通过以下命令去修改时区: ln -sf /usr/share/zo ...
- 如何在Jupyter里以不同的运行模式使用Pyspark
假设你的环境已经安装好了以下东西,如何详细的安装它们不在本文的讨论范围之内 具体的可疑参考三分钟搞定jupyter和pyspark整合 anaconda2 findspark pyspark 这里多说 ...
- Numpy基本操作
NumPy:数组计算 NumPy是高性能科学计算和数据分析的基础包.它是Pandas等其他各种工具的基础 NumPy的主要功能: ndarray,一个多维数据结构,高校且节省空间 无需循环即可对整组数 ...
- Linux程序宕掉后如何通过gdb查看出错信息
我们在编写服务端程序的时候,由于多线程并且环境复杂,程序可能在不确定条件的情况下宕掉,还不好重新,这是我们如何获取程序的出错信息,一种方法通过打日志,有时候一些错误日志也不能体现出来,这时就用到我们的 ...
- MT【281】最大值函数
已知正系数二次函数$ax^2+bx+c=0$有实数根,证明:$\max\{a,b,c\}\ge\dfrac{4}{9}(a+b+c)$ 证明:$\max\{a,b,c\}=\dfrac{a+c+|a- ...
- 【Spring】Spring Data JPA
原始JDBC操作数据库 传统JDBC方式实现数据库操作 package com.imooc.util; import java.io.InputStream; import java.sql.*; i ...
- mac/Linux/centos ssh连接服务器以及跳板机,实现类型Xshell 功能
1. 由于之前一段时间,公司测试服务器需要有跳板机这种操作,由于mac机器上没有类似Xshell这种程序,所以,只能自己造轮子啦. 本程序采用Shell+Expect脚本编写 具体代码请查看:http ...
- POJ--3974 Palindrome(回文串,hash)
链接:点击这里 #include<iostream> #include<algorithm> #include<stdio.h> #include<cstri ...
- 洛谷P4719 动态dp
动态DP其实挺简单一个东西. 把DP值的定义改成去掉重儿子之后的DP值. 重链上的答案就用线段树/lct维护,维护子段/矩阵都可以.其实本质上差不多... 修改的时候在log个线段树上修改.轻儿子所在 ...
- java 使用for循环打印杨辉三角形
首先需要说明的问题: 什么是杨辉三角形? 如图所示:杨辉三角形由数字排列,基本的特点是两侧的数值均为1,其它位置的数值是基正上方的数值与其左上方的数值之和. 代码实现: package test; i ...