/**
* 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) {
if(root == nullptr) return true;
else return inorder(root->left,root->right);
}
bool inorder(TreeNode* tree1, TreeNode* tree2){
if(tree1 == nullptr && tree2 == nullptr) return true;
else if(tree1 == nullptr || tree2 == nullptr) return false;
if(tree1->val!=tree2->val) return false;
else return inorder(tree1->left,tree2->right) &&inorder(tree1->right,tree2->left);
}
};
对称树应该用中序遍历,我脑子傻了开始用后序。。。