对称的二叉树

 

 1 class Solution {
 2 public:
 3     bool isSame(TreeNode* p1, TreeNode* p2)
 4     {
 5         if(!p1 && !p2)
 6             return true;
 7         if(!p1 || !p2)
 8             return false;
 9         if(p1->val == p2->val)
10             return isSame(p1->left,p2->right) && isSame(p1->right,p2->left);
11         else return false;
12     }
13     bool isSymmetrical(TreeNode* pRoot)
14     {
15        if(pRoot == NULL)
16            return true;
17         return isSame(pRoot,pRoot);
18     }
19 
20 };

 

posted on 2016-05-05 20:42  RenewDo  阅读(94)  评论(0编辑  收藏  举报

导航