LeetCode题解之 Subtree of Another Tree
1、题目描述

2、问题分析
判断一个节点,然后判断子树。
3、代码
bool isSubtree(TreeNode* s, TreeNode* t) {
if (s == NULL)
return false;
else {
return isSame(s,t) || isSubtree(s->left, t) || isSubtree(s->right, t);
}
}
bool isSame(TreeNode *t1, TreeNode *t2)
{
if (t1 == NULL && t2 == NULL) return true;
if (t1 == NULL || t2 == NULL) return false;
return (t1->val == t2->val) && isSame(t1->left, t2->left) && isSame(t1->right , t2->right);
}
LeetCode题解之 Subtree of Another Tree的更多相关文章
- LeetCode算法题-Subtree of Another Tree(Java实现)
这是悦乐书的第265次更新,第278篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第132题(顺位题号是572).给定两个非空的二进制树s和t,检查树t是否具有完全相同的 ...
- LeetCode题解:(114) Flatten Binary Tree to Linked List
题目说明 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 ...
- [LeetCode 题解]: Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 【leetcode】572. Subtree of Another Tree
题目如下: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure ...
- [LeetCode 题解]: Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- LeetCode题解之Find Bottom Left Tree Value
1.题目描述 2.问题分析 使用层序遍历思想 3.代码 int findBottomLeftValue(TreeNode* root) { if (root == NULL) ; queue<T ...
- LeetCode题解之Diameter of Binary Tree
1.题目描述 2.分析 深度优先. 3.代码 int ans; int diameterOfBinaryTree(TreeNode* root) { ans = ; depth(root); ; } ...
- LeetCode题解之 Increasing Order Search Tree
1.题目描述 2/问题分析 利用中序遍历,然后重新构造树. 3.代码 TreeNode* increasingBST(TreeNode* root) { if (root == NULL) retur ...
- [LeetCode 题解]: Binary Tree Preorder Traversal
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a bi ...
随机推荐
- SVN 分支主干的相互合并
1.主干合并到分支 1在本地trunk中先update一下,有冲突的解决冲突,保证trunk和repository已经完全同步, 2.在/branches /MyProject上右键,依次选择”Tor ...
- 移动端真机调试终极利器-BrowserSync(使用方法)
1. 安装 Node.js BrowserSync是基于Node.js的, 是一个Node模块, 如果您想要快速使用它,也许您需要先安装一下Node.js 安装适用于Mac OS,Windows和Li ...
- Go语言总结
- CountDownLatch 和 CyclicBarrier 的基本使用
CountDownLatch 和 CyclicBarrier 是并发编程中常用的辅助类,两者使用上有点类似,但又有不同. 一.CountDownLatch CountDownLatch 可是实现类似计 ...
- Linux_CentOS-服务器搭建 <二>
Tomat安装: 说明: 源码安装,下载地址:http://tomcat.apache.org/.我下了个apache-tomcat-7.0.42.tar.gz 安装开始: 配置环境. JDK: vi ...
- Shell脚本 | 安卓应用权限检查
现在 Google Play 对应用权限的管理非常严格,之前公司内有个版本就是因为新增了四个权限导致停灰处理.所以,在每个版本发布之前很有必要检查一下是否有新增权限. 安卓应用请求的所有权限可以通过 ...
- Dockerfile文件制作自己的镜像
1.创建空目录 $ cd /home/xm6f/dev $ mkdir myapp $ cd myapp/ 2.vim Dockerfile,内容如下: ## 一个基础的 python 运行环境 FR ...
- zookeeper ZAB协议 Follower和leader源码分析
Follower处理逻辑 void followLeader() throws InterruptedException { //... try { //获取leader server QuorumS ...
- lua脚本在游戏中的应用
为什么要在游戏中使用脚本语言? 要解释这个问题首先我们先来了解一下脚本语言的特性: 学习门槛低,快速上手 开发成本低,可维护性强 动态语言,灵活性高 相对于C/C++这类高复杂性.高风险的编译型语言来 ...
- Angular2入门:TypeScript的函数 - 剩余参数和箭头函数