return max(self.maxDepth(root.left), self.maxDepth(root.right))+1 if root else 0
LeetCode.111 二叉树的最小深度
def mindepth(node):
if not node: return inf
if node.left is node.right: return 1
return min(mindepth(node.left), mindepth(node.right))+1
return mindepth(root) if root else 0
LeetCode.559 N叉树的最大深度
return (max(self.maxDepth(i) for i in root.children)+1 if root.children else 1) if root else 0
LeetCode.222 完全二叉树的节点个数
return self.countNodes(root.left) + self.countNodes(root.right) + 1 if root else 0