MY 4ms RECURSIVE CODE


  • -6
    R

    class Solution {

    public:

    bool isSymmetric(TreeNode* root) {
        TreeNode * r1=root,*r2=root;
        return is_sym(r1,r2);
    }
    bool is_sym(TreeNode *r1,TreeNode *r2)
    {
        if(r1==NULL && r2==NULL)
        return true;
        if(r1==NULL || r2==NULL)
        return false;
        if(r1->val != r2->val)
        return false;
        return (is_sym(r1->left,r2->right) && is_sym(r1->right,r2->left));
    }
    

    };


  • 1
    M

    No, yelling "ITERATIVE" does not make a recursive solution iterative.


  • 0
    X

    liar...wast of our time


Log in to reply
 

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