We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 97c514d commit 49e7491Copy full SHA for 49e7491
maximum-depth-of-binary-tree/changhyumm.py
@@ -6,8 +6,11 @@
6
# self.right = right
7
class Solution:
8
def maxDepth(self, root: Optional[TreeNode]) -> int:
9
+ # root가 없는경우 depth 0
10
if root is None:
11
return 0
12
+ # depth를 같이 포함시킴
13
+ # dfs의 경우 각 경로별로 끝까지 탐색하는데, 각 경로마다 depth가 다르므로 표기하면서 stack에 추가해야함
14
stack = [[root, 1]]
15
max_depth = 1
16
while stack:
0 commit comments