6 lines c++ solution

  • 1
    class Solution {
        bool isSymmetric(TreeNode* root) {
            if(!root)return true;
            return g(root->left,root->right);
        bool g(TreeNode*n,TreeNode*p){
            if(!n&&!p) return true;
            if(!n||!p) return false;
            return n->val == p->val && g(n->left,p->right) && g(n->right,p->left);

  • 0

    Beautiful solution, but I can‘t come up with it. ^_^

Log in to reply

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