Skip to content

Commit

Permalink
feat: 104.maximum-depth-of-binary-tree add Python3 implementation (az…
Browse files Browse the repository at this point in the history
  • Loading branch information
ybian19 authored and azl397985856 committed Aug 4, 2019
1 parent 6b01607 commit 442151d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion problems/104.maximum-depth-of-binary-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var maxDepth = function(root) {
- 树的基本操作- 遍历 - 层次遍历(BFS)

## 代码
* 语言支持:JS,C++
* 语言支持:JS,C++,Python

JavaScript Code:
```js
Expand Down Expand Up @@ -130,6 +130,23 @@ public:
}
};
```
Python Code:
```python
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if not root: return 0
q, depth = [root, None], 1
while q:
node = q.pop(0)
if node:
if node.left: q.append(node.left)
if node.right: q.append(node.right)
elif q:
q.append(None)
depth += 1
return depth
```
## 相关题目
- [102.binary-tree-level-order-traversal](./102.binary-tree-level-order-traversal.md)
- [103.binary-tree-zigzag-level-order-traversal](./103.binary-tree-zigzag-level-order-traversal.md)

0 comments on commit 442151d

Please sign in to comment.