101. Symmetric Tree

class Solution {
public:
    bool isSymmetric2(TreeNode* lr,TreeNode* rr) {
        if(!lr&&!rr) return true;
        else if(!lr&&rr) return false;
        else if(lr&&!rr) return false;
        else if(lr->val!=rr->val) return false;
        else return isSymmetric2(lr->left,rr->right)&&isSymmetric2(lr->right,rr->left);
    }
    bool isSymmetric(TreeNode* root) {
        if(!root) return true;
        return isSymmetric2(root->left,root->right);
    }
};

猜你喜欢

转载自blog.csdn.net/qq_41098649/article/details/80490293