Simple and clean recursive solution c++


  • 0
    C

    class Solution {
    public:
    bool isSymmetric(TreeNode* root) {
    if(root==NULL) return true;
    return help_isSymmetric(root->left,root->right);
    }
    bool help_isSymmetric(TreeNode* left, TreeNode* right)
    {
    if(left==NULL && right==NULL) return true;
    if(left==NULL || right==NULL) return false;
    if(left->val!=right->val) return false;
    return help_isSymmetric(left->right,right->left) && help_isSymmetric(left->left,right->right);
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.