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 ...
随机推荐
- 如何优雅的处理Nodejs中的异步回调
前言 Nodejs最大的亮点就在于事件驱动, 非阻塞I/O 模型,这使得Nodejs具有很强的并发处理能力,非常适合编写网络应用.在Nodejs中大部分的I/O操作几乎都是异步的,也就是我们处理I/O ...
- 【转载】nedmalloc结构分析
原文:nedmalloc结构分析 nedmalloc是一个跨平台的高性能多线程内存分配库,很多库都使用它,例如:OGRE.现在我们来看看nedmalloc的实现 (以WIN32部分为例) 位操作 ...
- 自动编号维护SNRO
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [SAP ABAP开发技术总结]FTP到文件服务器,服务器上文件读写
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- CUBRID学习笔记 11 数据类型之日期
datetime 虽然和mysql很相像,但是日期类型和mysql是不一样的.和sqlserver差不多. 如YYYY-MM-DD hh:mi:ss.fff or mm/dd/yyyy hh:mi:s ...
- MySQL多表更新(逻辑外键/事实外键)
语法结构: UPDATE table_reference SET 列名1=value1[,列名2=value2,......] [WHERE where_condition] 说明: tabl ...
- FZU 2219 StarCraft(星际争霸)
Description 题目描述 ZB loves playing StarCraft and he likes Zerg most! One day, when ZB was playing SC2 ...
- hdu 3535 AreYouBusy 分组背包
AreYouBusy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- 杭电1466------简单的dp
题目: http://acm.hdu.edu.cn/showproblem.php?pid=1466 #include<iostream> #include<cstdio> # ...
- VS2012创建MVC3项目提示错误: 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。
如果在没有安装vs2012 update3升级包的情况下,创建MVC3项目会出现下面的错误信息. 因为VS2012已经全面切换到使用NuGet这个第三方开源工具来管理项目包和引用模块了,使用VS201 ...