smj007

Untitled

Jun 19th, 2022 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. class Solution:
  2.     def maxDepth(self, root: Optional[TreeNode]) -> int:
  3.        
  4.         if not root:
  5.             return 0
  6.        
  7.         return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
  8.  
  9. class Solution:
  10.     def maxDepth(self, root: Optional[TreeNode]) -> int:
  11.  
  12.         if root is None:
  13.             return 0
  14.  
  15.         left_count = self.maxDepth(root.left)
  16.         right_count = self.maxDepth(root.right)
  17.  
  18.         return 1 + max(left_count, right_count)
Advertisement
Add Comment
Please, Sign In to add comment