3ms C++ solution


  • 0
    S

    class Solution {

    public:
        bool isSymmetric(TreeNode* root) {
            if (root == NULL) return true;
            if (root->left == NULL && root->right == NULL) return true;
            return twoNodes(root->left,root->right);
        }
        bool twoNodes(TreeNode* L, TreeNode* R){
            if (L == NULL && R == NULL) return true;
            if ( (L == NULL) ^ (R == NULL)) return false;
            if (L->val == R->val) return twoNodes(L->left,R->right)&&twoNodes(L->right,R->left);
            else return false;
        }
    };

Log in to reply
 

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