码迷,mamicode.com
首页 > 其他好文 > 详细

LintCode: Identical Binary Tree

时间:2016-01-06 15:28:09      阅读:136      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!