Skip to content

Commit 772b3c1

Browse files
committed
LeetCode: 104 solved
1 parent 490d862 commit 772b3c1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# https://leetcode.com/problems/maximum-depth-of-binary-tree/
2+
3+
# Definition for a binary tree node.
4+
class TreeNode:
5+
def __init__(self, val=0, left=None, right=None):
6+
self.val = val
7+
self.left = left
8+
self.right = right
9+
10+
class Solution:
11+
def maxDepth(self, root: TreeNode) -> int:
12+
if not root:
13+
return 0
14+
if not root.left and not root.right:
15+
return 1
16+
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))

0 commit comments

Comments
 (0)