The perfact C++ code use recursive.


  • -1
    W
    class Solution {
    public:
        bool isSymmetric(TreeNode* l, TreeNode* r) {
            if (l == NULL || r == NULL) return l==r;
            return (l->val == r->val) && isSymmetric(l->left, r->right) && isSymmetric(l->right, r->left);
        }
        bool isSymmetric(TreeNode* root) {
            return root == NULL || isSymmetric(root->left, root->right);
        }
    };

  • 0
    Z

    How come this is PERFECT?


Log in to reply
 

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