Skip to content

Commit 0e8308b

Browse files
committed
feat(leetcode): solve 124 - Binary Tree Maximum Path Sum
1 parent e35ca04 commit 0e8308b

5 files changed

Lines changed: 47 additions & 16 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ Total 125
2222
2323
| Field | Value |
2424
|------|------|
25-
| Problem ID | 789 |
26-
| Title | Kth Largest Element In A Stream |
25+
| Problem ID | 124 |
26+
| Title | Binary Tree Maximum Path Sum |
2727
| Language | Python3 |
28-
| Runtime | 16 ms |
29-
| Memory | 25.5 MB |
28+
| Runtime | 4 ms |
29+
| Memory | 23.9 MB |
3030
3131
3232
💻 Languages Used
3333
34-
- **Python3** : 22
34+
- **Python3** : 23
3535
3636
## 📚 Recent Accepted Problems
3737
38+
- 124 Binary Tree Maximum Path Sum
3839
- 789 Kth Largest Element In A Stream
3940
- 1127 Last Stone Weight
4041
- 1014 K Closest Points To Origin
4142
- 295 Find Median From Data Stream
42-
- 11 Container With Most Water
4343
4444
4545
---
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"submission_id": "2048068140",
3+
"question_id": "124",
4+
"title_slug": "binary-tree-maximum-path-sum",
5+
"language": "python3",
6+
"language_verbose": "Python3",
7+
"runtime": "4 ms",
8+
"memory": "23.9 MB",
9+
"status_code": 10,
10+
"timestamp": 1782579555
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
def maxPathSum(self, root: Optional[TreeNode]) -> int:
9+
self.ans=float('-inf')
10+
def dfs(node):
11+
if not node:
12+
return 0
13+
left=max(dfs(node.left),0)
14+
right = max(dfs(node.right),0)
15+
16+
self.ans=max(self.ans, node.val+ left+ right)
17+
18+
return node.val + max(left, right)
19+
dfs(root)
20+
return self.ans

storage/state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"last_submission_id": "2050286655"
2+
"last_submission_id": "2050276621"
33
}

storage/stats.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"medium": 56,
55
"hard": 6,
66
"languages": {
7-
"Python3": 22
7+
"Python3": 23
88
},
99
"recent_problems": [
10+
{
11+
"id": "124",
12+
"title": "Binary Tree Maximum Path Sum"
13+
},
1014
{
1115
"id": "789",
1216
"title": "Kth Largest Element In A Stream"
@@ -22,18 +26,14 @@
2226
{
2327
"id": "295",
2428
"title": "Find Median From Data Stream"
25-
},
26-
{
27-
"id": "11",
28-
"title": "Container With Most Water"
2929
}
3030
],
3131
"last_problem": {
32-
"id": "789",
33-
"title": "Kth Largest Element In A Stream",
32+
"id": "124",
33+
"title": "Binary Tree Maximum Path Sum",
3434
"language": "Python3",
35-
"runtime": "16 ms",
36-
"memory": "25.5 MB"
35+
"runtime": "4 ms",
36+
"memory": "23.9 MB"
3737
},
3838
"last_sync": "2026-07-06 19:56:23"
3939
}

0 commit comments

Comments
 (0)