Skip to content

Commit 9ea4c6c

Browse files
committed
Add comments
1 parent 00a15f0 commit 9ea4c6c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

binary-tree-maximum-path-sum/doh6077.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ def dfs(root):
3636
return 0
3737
leftMax = dfs(root.left)
3838
rightMax = dfs(root.right)
39+
# 자식 값이 음수일경우 0으로 처리
3940
leftMax = max(leftMax, 0)
4041
rightMax = max(rightMax, 0)
41-
42+
# "지금까지 발견한 경로 중 최고의 합"을 res[0]에 저장
43+
# Job 1: 나를 꺾임점(Anchor)으로 하는 '아치형' 경로 계산
4244
res[0] = max(res[0], root.val + leftMax + rightMax)
43-
45+
# Job 2: 부모에게 올릴 '직선' 경로 리턴
4446
return root.val + max(leftMax, rightMax)
4547
dfs(root)
4648
return res[0]

0 commit comments

Comments
 (0)