【leetcode】Same Tree(easy)
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.
思路:太简单!
bool isSameTree(TreeNode *p, TreeNode *q) {
if(p == NULL && q == NULL) return true;
else if(p == NULL || q == NULL) return false;
else if(p->val != q->val) return false;
else
{
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
}
【leetcode】Same Tree(easy)的更多相关文章
- 【leetcode】Happy Number(easy)
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
- 【leetcode】Remove Element (easy)
Given an array and a value, remove all instances of that value in place and return the new length. T ...
- 【leetcode】Min Stack(easy)
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 【leetcode】Count Primes(easy)
Count the number of prime numbers less than a non-negative number, n 思路:数质数的个数 开始写了个蛮力的,存储已有质数,判断新数字 ...
- 【BZOJ】1468: Tree(POJ1741) 点分治
[题意]给定带边权树,求两点距离<=k的点对数.n<=40000. [算法]点分治 [题解]对于一个区域,选择其重心x作为根,则划分出来的每棵子树都是子区域,可以证明至多划分log n次( ...
- 【转】Device Tree(三):代码分析
原文网址:http://www.wowotech.net/linux_kenrel/dt-code-analysis.html 一.前言 Device Tree总共有三篇,分别是: 1.为何要引入De ...
- 【转】Device Tree(二):基本概念
原文网址:http://www.wowotech.net/linux_kenrel/dt_basic_concept.html 一.前言 一些背景知识(例如:为何要引入Device Tree,这个机制 ...
- 【3】Decision tree(决策树)
前言 Decision tree is one of the most popular classification tools 它用一个训练数据集学到一个映射,该映射以未知类别的新实例作为输入,输出 ...
- 【leetcode】Reverse Integer(middle)☆
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 总结:处理整数溢出 ...
随机推荐
- RTX二次开发(一)(基于ASP.NET)
腾讯通RTX是(Real Time eXpert)是腾讯公司推出的企业级实时通信平台,致力于帮助企业提高运作效率.降低沟通成本.拓展商业机会,是一种高度可管理.低成本.易部署的IT平台.RTX集成了丰 ...
- VTK初学一,b_PolyVertex多个图形点的绘制
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- 《JavaScript DOM 编程艺术(第2版)》读书笔记
阅读了本书第五章关于使用JavaScript的最佳实践,大部分的建议之前都有耳闻,不过阅读之后有更深的体会. 1.防止滥用JavaScript “不管你想通过JavaScript改变哪个网页的行为,都 ...
- ScriptManager与UpdatePanel总结
1.From http://www.cnblogs.com/Tim-Seven/archive/2011/02/11/1952409.html Ajax Extensions 2.ScriptMana ...
- java框架
Dash Reports 1.0发布 Java报表解决方案 http://developer.51cto.com/art/201205/337189.htm http://www.oschina.ne ...
- JS补充
JavaScript JavaScript 使用那些老旧的实例可能会在 <script> 标签中使用 type="text/javascript".现在已经不必这样做了 ...
- 关联规则之Aprior算法(购物篮分析)
0.支持度与置信度 <mahout实战>与<机器学习实战>一起该买的记录数占所有商品记录总数的比例——支持度(整体) 买了<mahout实战>与<机器学习实战 ...
- 【Go入门教程8】总结(25个关键字)
这一章我们主要介绍了Go语言的一些语法,通过语法我们可以发现Go是多么的简单,只有二十五个关键字.让我们再来回顾一下这些关键字都是用来干什么的. break default func ...
- JS快速获取图片宽高的方法
快速获取图片的宽高其实是为了预先做好排版样式布局做准备,通过快速获取图片宽高的方法比onload方法要节省很多时间,甚至一分钟以上都有可能,并且这种方法适用主流浏览器包括IE低版本浏览器. 我们一步一 ...
- Java中Runnable和Thread
java中有两种实现多线程的方式:一种是继承Thread类,一种是实现Runnable接口. 1.java启动线程为什么使用start函数呢? 在JDK的安装路径下,src.zip是全部的java源程 ...