还有BFS的解法,后面补齐
//0027对称二叉树
class Solution {
public:
//对称的含义就是镜像:左节点的左子树==右节点的右子树
// 右节点的左子树==左节点的右子树
bool Dfs(TreeNode *p, TreeNode *q)
{
if (!q || !p) return !q && !p;
return q -> val == p -> val && Dfs(p -> left, q -> right) && Dfs(p -> right, q -> left);
}
bool isSymmetric(TreeNode* root) {
return !root || Dfs(root -> left, root -> right);
}
};