104.二叉树的最大深度
func maxDepth(root *TreeNode) int {
if root==nil{
return 0
}
leftDepth := maxDepth(root.Left)
rightDepth := maxDepth(root.Right)
if leftDepth<rightDepth{
return rightDepth+1
}else{
return leftDepth+1
}
}
101对称二叉树
func isSymmetric(root *TreeNode) bool {
return check(root, root)
}
// 这个函数是用来判断p和q结点是否对称
func check(p *TreeNode, q *TreeNode)bool{
// 退出条件
if p==nil && q==nil{
return true
}
if p==nil || q==nil{
return false
}
return p.Val==q.Val && check(p.Left,q.Right) && check(p.Right,q.Left)
}