4ms c++ solution recursive


  • 0
    Q
    class Solution {
    public:
        bool isSymmetricPro(TreeNode* node1, TreeNode* node2){
            if(node1 == NULL && node2 == NULL)
                return true;
            if(node1 == NULL || node2 == NULL || node1->val != node2->val)
                return false;
            return isSymmetricPro(node1->left, node2->right) && isSymmetricPro(node1->right, node2->left);
        }
        bool isSymmetric(TreeNode* root) {
            return (root == NULL)?true:isSymmetricPro(root->left, root->right);
        }
    };

Log in to reply
 

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