For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following is not:
1 / \ 2 2 \ \ 3 3
bool isSymmetric(TreeNode *Left,TreeNode *Right)
{
if(!Left&&!Right)
return true;
if(!Left||!Right)
return false;
if(Left->val==Right->val)
return isSymmetric(Left->left,Right->right)&&isSymmetric(Left->right,Right->left);
return false;
}
bool isSymmetric(TreeNode *root)
{
if(!root)
return true;
return isSymmetric(root->left,root->right);
}