Skip to content

Commit b98577d

Browse files
solve smax depth / height of binary tree
1 parent ccdf72b commit b98577d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![problems-solved](https://img.shields.io/badge/Problems%20Solved-107/571-1f425f.svg)
44
![problems-solved-java](https://img.shields.io/badge/Java-107/1571-1abc9c.svg)
5-
![problems-solved-python](https://img.shields.io/badge/Python-31/1571-1abc9c.svg)
5+
![problems-solved-python](https://img.shields.io/badge/Python-32/1571-1abc9c.svg)
66
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
77

88
## Problems
@@ -30,7 +30,7 @@
3030
| 88 | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MergeSortedArray.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/merge_sorted_array.py) |
3131
| 100 | [Same Tree](https://leetcode.com/problems/same-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SameTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/same_tree.py) |
3232
| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/SymmetricTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/symmetric_tree.py) |
33-
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) |
33+
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MaximumDepthOfBinaryTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/maximum_depth_of_binary_tree.py) |
3434
| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BinaryTreeLevelOrderTraversalII.java) |
3535
| 108 | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ConvertSortedArrayToBinarySearchTree.java) |
3636
| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/BalancedBinaryTree.java) |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Definition for a binary tree node.
2+
class TreeNode:
3+
def __init__(self, val=0, left=None, right=None):
4+
self.val = val
5+
self.left = left
6+
self.right = right
7+
8+
9+
class Solution:
10+
def maxDepth(self, root: TreeNode) -> int:
11+
if root is None:
12+
return 0
13+
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))

0 commit comments

Comments
 (0)