7.12 note
对称二叉树
class Solution {
public:
bool isSymmetric(TreeNode* root)
{
if(!root) return true;
return com(root->left,root->right);
}
bool com(TreeNode* left,TreeNode* right)
{
//对称
if(!left && !right)
return true;
if(!left ||!right)
return false;
return (left->val==right->val)
&& com(left->left,right->right)
&& com(left->right,right->left);
}
};