Skip to content

Commit 50a97b9

Browse files
authored
Added the solution of Maximum Depth of Binary Tree (#119)
* Binary Tree Inorder Traversal with recursion * Update README.md * Binary Tree Inorder Traversal with recursion * Update README.md added maximum depth * Update README.md
1 parent 1c07823 commit 50a97b9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Python/binary-tree-inorder-traversal.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#Time Complexity: O(n)
2+
#Space Complexity: O(n)
3+
#Speed: 78.92%
4+
#Memory: 99.97%
5+
16
# Definition for a binary tree node.
27
# class TreeNode:
38
# def __init__(self, val=0, left=None, right=None):
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Time Complexity: O(n)
2+
#Space Complexity: O(n)
3+
#Speed: 98.14%
4+
#Memory: 50.93%
5+
6+
# Definition for a binary tree node.
7+
# class TreeNode:
8+
# def __init__(self, val=0, left=None, right=None):
9+
# self.val = val
10+
# self.left = left
11+
# self.right = right
12+
class Solution:
13+
def maxDepth(self, root: TreeNode) -> int:
14+
if root is None:
15+
return 0
16+
else:
17+
return max(self.maxDepth(root.left)+1, self.maxDepth(root.right)+1)

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
295295

296296
| # | Title | Solution | Time | Space | Difficulty | Tag | Note |
297297
| ---- | ------------------------------------------------------------------- | --------------------------------- | ----------- | ----------- | ---------- | --- | ---- |
298-
| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | |
298+
| 1463 | [Cherry Pickup II](https://leetcode.com/problems/cherry-pickup-ii/) | [C++](./C++/Cherry-Pickup-II.cpp) | _O(n \* m)_ | _O(n \* m)_ | Hard | DFS | |
299+
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | |
299300

300301
<br/>
301302
<div align="right">

0 commit comments

Comments
 (0)