My simple c++ solution


  • 0
    B
    class Solution {
    public:
        bool isSymmetric(TreeNode* root) {
            return (!root || IsEqual(root->left, root->right));
        }
    private:
        bool IsEqual (TreeNode* left, TreeNode* right) {
            if(left && right && left->val==right->val)
                return IsEqual(left->left, right->right) && IsEqual(left->right, right->left);
            return !left && !right;
        }
    };

Log in to reply
 

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