提交 d551a942 编写于 作者: L laozhang

python leetcode 55

上级 02cb349d
...@@ -8,3 +8,4 @@ ...@@ -8,3 +8,4 @@
## 二叉树专题 ## 二叉树专题
1. [二叉树的镜像](./solution/tree/leetcode_27_.py) 1. [二叉树的镜像](./solution/tree/leetcode_27_.py)
1. [二叉树的深度](./solution/tree/leetcode_55_.py)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# coding=utf-8
"""
27. 二叉树的镜像
"""
from solution import TreeNode
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if root is None:
return 0
leftDepth = self.maxDepth(root.left) + 1
rightDepth = self.maxDepth(root.right) + 1
return leftDepth if leftDepth > rightDepth else rightDepth
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册