C++ , do what you can do to solve


  • 0
    B

    /**

    • Definition for a binary tree node.
    • struct TreeNode {
    • int val;
      
    • TreeNode *left;
      
    • TreeNode *right;
      
    • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
      
    • };
      /
      class Solution {
      bool reSymmetric(TreeNode
      left,TreeNode* right)
      {
      if(left == NULL && right == NULL)
      {
      return true;
      }
      else if(left != NULL && right == NULL)
      return false;
      else if(left == NULL && right != NULL)
      return false;
      else if((left != NULL) && (right != NULL) && (left->val != right->val))
      {
      return false;
      }
      else
      return reSymmetric(left->left,right->right)&&reSymmetric(left->right,right->left);
      }
      public:
      bool isSymmetric(TreeNode* root) {
      if(root == NULL)
      return true;
      else
      return reSymmetric(root->left,root->right);
      }
      };

Log in to reply
 

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