leetcode-101-树题-对称二叉树 发表于 2020-03-20 | 分类于 数据结构与算法 题目 解法1234567891011121314151617181920212223/** * 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 {public: bool isSymmetric(TreeNode* root) { return symmetricCore(root, root); } bool symmetricCore(TreeNode *s1, TreeNode *s2) { if(!s1 && !s2) return true; if(!s1 || !s2) return false; if(s1->val != s2->val) return false; return symmetricCore(s1->left, s2->right) && symmetricCore(s1->right, s2->left); }};