My simple c++ solution


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

Log in to reply
 

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