Clean c++ code 9ms


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

Log in to reply
 

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