This commit is contained in:
Gyubin Han
2025-02-19 14:09:55 +09:00
parent e3c6c8b32a
commit dede0dca01
36 changed files with 555 additions and 0 deletions

13
leetcode/104.py Normal file
View File

@@ -0,0 +1,13 @@
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def depth(self,now:Optional[TreeNode],depth:int):
if now==None:
return depth-1
return max(self.depth(now.left,depth+1),self.depth(now.right,depth+1),depth)
def maxDepth(self, root: Optional[TreeNode]) -> int:
return self.depth(root,1)