101.对称二叉树
题目链接
class Solution {
public:
bool issame(TreeNode* a, TreeNode* b){
if(a == NULL && b == NULL)return true;
if(a == NULL || b == NULL)return false;
if(a -> val != b -> val)return false;
if(!issame(a->left, b->right))return false;
if(!issame(a->right, b->left))return false;
return true;
}
bool isSymmetric(TreeNode* root) {
return issame(root, root);
}
};
104.二叉树的最大深度
题目链接
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == NULL)return 0;
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
};