[LintCode]469.等价二叉树
来源:互联网 发布:印度fdi数据 编辑:程序博客网 时间:2024/06/06 02:07
检查两棵二叉树是否等价。等价的意思是说,首先两棵二叉树必须拥有相同的结构,并且每个对应位置上的节点上的数都相等。
样例
1 1 / \ / \ 2 2 and 2 2 / /4 4
就是两棵等价的二叉树。
1 1 / \ / \ 2 3 and 2 3 / \4 4
就不是等价的。
/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */class Solution {public: /* * @param a: the root of binary tree a. * @param b: the root of binary tree b. * @return: true if they are identical, or false. */ bool isIdentical(TreeNode * a, TreeNode * b) { if(a==NULL&&b==NULL) return true; //if((a!=NULL&&b==NULL)||(a==NULL&&b!=NULL)) return false; if(a!=NULL&&b!=NULL && a->val==b->val ){ return isIdentical(a->left,b->left)&&isIdentical(a->right,b->right); } return false; }};
阅读全文
0 0
- LintCode - 469.等价二叉树
- [LintCode]469.等价二叉树
- LintCode:等价二叉树
- lintcode ----等价二叉树
- 等价二叉树-lintcode
- 等价二叉树,lintcode
- lintcode-->等价二叉树
- lintcode,等价二叉树
- LintCode-等价二叉树
- LIntCode 等价二叉树
- 等价二叉树-LintCode
- Lintcode 等价二叉树
- LintCode 等价二叉树
- 等价二叉树-LintCode
- lintcode 469 等价二叉树
- LintCode 469-等价二叉树
- [Lintcode] #469 等价二叉树
- lintCode(469)——等价二叉树
- MySQL基础习题锻炼(二)
- 爬虫入门1:urllib.parse
- 跟老师的例子写的第一个驱动
- 浅谈static关键字和extern关键字
- (1)深入理解java虚拟机笔记整理之垃圾收集那点事儿
- [LintCode]469.等价二叉树
- 什么是 哈希表 HashMap 中数组的 size 为什么必须是 2 的整数次幂
- 图片上传的jsp-项目可借鉴-可基于自身调整样式
- js选择排序
- 12打印1到最大的n位数python***
- 通过python简单操作MySQL
- 速查笔记(Linux Shell编程<下>)
- 从mvc到前后端分离
- C++中的const,引用,和指针