226. 翻转二叉树
class Solution {
public:
void invert(TreeNode* root)
{
if(root==nullptr) return;
TreeNode* node=root->left;
root->left=root->right;
root->right=node;
invertTree(root->left);
invertTree(root->right);
}
TreeNode* invertTree(TreeNode* root) {
invert(root);
return root;
}
};
101. 对称二叉树
class Solution {
public:
bool issame(TreeNode* left,TreeNode* right)
{
if(left==nullptr&&right==nullptr) return true;
else if(left!=nullptr&&right==nullptr) return false;
else if(right!=nullptr&&left==nullptr) return false;
else if(left->val!=right->val) return false;
else return issame(left->left,right->right)&&issame(left->right,right->left);
}
bool isSymmetric(TreeNode* root) {
return issame(root->left,root->right);
}
};
需要重新做的题目
101. 对称二叉树
572. 另一棵树的子树