-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxDepth.py
More file actions
16 lines (15 loc) · 514 Bytes
/
Copy pathmaxDepth.py
File metadata and controls
16 lines (15 loc) · 514 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
# https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
def maxDepth(self, root: TreeNode) -> int:
if not root:
return 0
leftDepth = self.maxDepth(root.left)
rightDepth = self.maxDepth(root.right)
depth = (leftDepth if leftDepth > rightDepth else rightDepth) + 1
return depth