Recursive c++ code.


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

Log in to reply
 

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