Skip to content

Commit afdd5ed

Browse files
committed
Refactor maxDepth function implementation for clarity and conciseness
1 parent 97931a0 commit afdd5ed

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

maximum-depth-of-binary-tree/gcount85.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
# Intuition
33
1) BFS + 큐
44
2) DFS + 재귀
5-
1번으로 풀었다가 2번이 코드가 더 간결해서 바꿨습니다.
5+
1번으로 풀었다가 2번이 코드가 더 간결해서 바꿨습니다.
66
77
# Complexity
88
- Time complexity: 모든 노드를 다 봐야 하므로 O(N)
99
1010
- Space complexity: 재귀 깊이만큼 O(H)
1111
"""
1212

13+
1314
class Solution:
1415
def maxDepth(self, root: Optional[TreeNode]) -> int:
1516
if not root:
1617
return 0
1718
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
18-
19-

0 commit comments

Comments
 (0)