4 line C++ code


  • 0
    1

    class Solution {
    public:
      bool isSymmetric(TreeNode* root) {
        return dfs(root,root);
      }
      bool dfs(TreeNode* a, TreeNode *b){
        if(a == NULL && b == NULL) return true;
        else if(a == NULL || b == NULL || a->val != b->val) return false;
        return dfs(a->right, b->left) && dfs(a->left, b->right);
     }
    };


Log in to reply
 

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