首页 > 其他 > 详细

LintCode: Identical Binary Tree

时间:2016-01-06 15:28:08      阅读:141      评论:0      收藏:0      [点我收藏+]

C++

 1 /**
 2  * Definition of TreeNode:
 3  * class TreeNode {
 4  * public:
 5  *     int val;
 6  *     TreeNode *left, *right;
 7  *     TreeNode(int val) {
 8  *         this->val = val;
 9  *         this->left = this->right = NULL;
10  *     }
11  * }
12  */
13 class Solution {
14 public:
15     /**
16      * @aaram a, b, the root of binary trees.
17      * @return true if they are identical, or false.
18      */
19     bool isIdentical(TreeNode* a, TreeNode* b) {
20         // Write your code here
21         if (a == NULL && b == NULL) {
22             return true;
23         }
24         if (a == NULL || b == NULL) {
25             return false;
26         }
27         if (a->val != b->val) {
28             return false;
29         }
30         return isIdentical(a->left, b->left) && isIdentical(a->right, b->right);
31     }
32 };

 

LintCode: Identical Binary Tree

原文:http://www.cnblogs.com/CheeseZH/p/5105595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!