首页 > 代码库 > LeetCode "Symmetric Tree"

LeetCode "Symmetric Tree"

Recursive.

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