Leetcode#101 Symmetric Tree

原题地址

 

递归比较左儿子和右儿子是否对称,左儿子的左儿子跟右儿子的右儿子比,左儿子的右儿子跟右儿子的左儿子比!打完这一串文字突然发现"儿"字怎么这么奇怪!

 

代码:

 1 bool mirrorp(TreeNode *a, TreeNode *b) {
 2   if (a && b)
 3     return a->val == b->val && mirrorp(a->left, b->right) && mirrorp(a->right, b->left);
 4   else
 5     return a == b;
 6 }
 7 
 8 bool isSymmetric(TreeNode *root) {
 9   return !root || mirrorp(root->left, root->right);
10 }

 

posted @ 2015-02-02 11:04  李舜阳  阅读(197)  评论(0编辑  收藏  举报