Skip to content

Commit 3c6d744

Browse files
committed
Adding Simple Solution for Problem - 104 - Maximum Depth BT
1 parent 473f281 commit 3c6d744

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Maximum_Depth_BT/SimpleSolution.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 104
6+
## Problem Name: Maximum Depth of Binary Tree
7+
##===================================
8+
#
9+
#Given a binary tree, find its maximum depth.
10+
#
11+
#The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
12+
#
13+
#Note: A leaf is a node with no children.
14+
#
15+
#Example:
16+
#
17+
#Given binary tree [3,9,20,null,null,15,7],
18+
#
19+
# 3
20+
# / \
21+
# 9 20
22+
# / \
23+
# 15 7
24+
#return its depth = 3.
25+
class Solution:
26+
def maxDepth(self, root):
27+
if root is None: #Condition-check:If root is empty
28+
return 0 #We return zero, as depth is zero for base case
29+
else: #Condition-check:Else
30+
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) #We return total depth of tree by using recursion

0 commit comments

Comments
 (0)