Same Tree [LeetCode]
Problem Description: http://oj.leetcode.com/problems/same-tree/
class Solution {
public:
bool isSameTree(TreeNode *p, TreeNode *q) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(p == NULL && q == NULL)
return true;
if(p == NULL && q != NULL ||
(p != NULL && q == NULL))
return false;
if(p->val != q->val)
return false;
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
};
Same Tree [LeetCode]的更多相关文章
- Symmetric Tree [LeetCode]
Problem description: http://oj.leetcode.com/problems/symmetric-tree/ Basic idea: Both recursive and ...
- Minimum Depth of Binary Tree ——LeetCode
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Balanced Binary Tree [LeetCode]
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- Minimum Depth of Binary Tree [LeetCode]
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- 110.Balanced Binary Tree Leetcode解题笔记
110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- Convert Sorted Array to Binary Search Tree || LeetCode
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...
- Validate Binary Search Tree [LeetCode]
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
- Recover Binary Search Tree [LeetCode]
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- Lowest Common Ancestor of a Binary Tree——Leetcode
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...
随机推荐
- linux 查找替换
esc: 命令模式与插入模式的切换 一.vi查找: 当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢?在vi里可没有菜单-〉查找, 不过没关系,你在命令模式下敲斜杆( ...
- 粒子群优化算法(Particle Swarm Optimization)
粒子群算法的思想源于对鸟/鱼群捕食行为的研究,模拟鸟集群飞行觅食的行为,鸟之间通过集体的协作使群体达到最优目的,是一种基于Swarm Intelligence的优化方法.它没有遗传算法的"交 ...
- 单向和双向tvs管
tvs管器件按极性可分为单极性和双极性两种,即单向tvs管和双向tvs管. 单向tvs管保护器件仅能对正脉冲或者负脉冲进行防护,而双向tvs管保护器件一端接要保护的线路,一端接地,无论来自反向还 ...
- XSS技巧综合
这周六会在公司分享经验和技巧,把自己的和网上的一些技巧来综合写一些,方便大家和自己: 普通的XSS,储存,反射,DOM 形成的无外乎就是输出点在html标签之间,html属性之间,成为JS代码,称为C ...
- loutsScript 常用代码
1.FTSearch搜索: Set dc=db.Ftsearch("name",0) '0位置为最大的查询数,0为所有匹配的文件 FTSearch必须创建数据库索引 Set doc ...
- 数据库mysql中having 和where的区别
having的用法 having字句可以让我们筛选成组后的各种数据,where字句在聚合前先筛选记录,也就是说作用在group by和having字句前.而 having子句在聚合后对组记录进行筛选. ...
- iOS - Swift SingleClass 单例类
前言 单例对象能够被整个程序所操作.对于一个单例类,无论初始化单例对象多少次,也只能有一个单例对象存在,并且该对象是全局的,能够被整个系统访问到. 单例类的创建 1.1 单例类的创建 1 单例类的创建 ...
- jsp的el表达式
el表达式的英文(Expression Language) 1.访问 javabean,list,map,数组 2.可以进行一些运算 3.获得web开发的常用对象 导入jstl.jar和stander ...
- 10 database tables
本章提要-----------------------------------各种数据库表的讨论, 并介绍什么情况使用哪种表情调表的物理存储特征---------------------------- ...
- 下载安装APK
protected void downloadApk() { //apk下载链接地址,放置apk的所在路径 //1,判断sd卡是否可用,是否挂在上 if(Environment.getExternal ...