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 00a15f0 commit 9ea4c6cCopy full SHA for 9ea4c6c
1 file changed
binary-tree-maximum-path-sum/doh6077.py
@@ -36,11 +36,13 @@ def dfs(root):
36
return 0
37
leftMax = dfs(root.left)
38
rightMax = dfs(root.right)
39
+ # 자식 값이 음수일경우 0으로 처리
40
leftMax = max(leftMax, 0)
41
rightMax = max(rightMax, 0)
-
42
+ # "지금까지 발견한 경로 중 최고의 합"을 res[0]에 저장
43
+ # Job 1: 나를 꺾임점(Anchor)으로 하는 '아치형' 경로 계산
44
res[0] = max(res[0], root.val + leftMax + rightMax)
45
+ # Job 2: 부모에게 올릴 '직선' 경로 리턴
46
return root.val + max(leftMax, rightMax)
47
dfs(root)
48
return res[0]
0 commit comments