leetcode-101-对称二叉树
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isMirrored(TreeNode* p, TreeNode* q){
if (!p && !q) return true;
bool res;
if (p && q){
if (p->val != q->val) return false;
res = isMirrored(p->left, q->right) && isMirrored(p->right, q->left);
}
else return false;
return res;
}
bool isSymmetric(TreeNode* root) {
if (!root) return true;
return (isMirrored(root->left, root->right));
}
};