Skip to content

Commit d7841b7

Browse files
committed
feat(leetcode): solve 235 - Lowest Common Ancestor Of A Binary Search Tree
1 parent 0e8308b commit d7841b7

5 files changed

Lines changed: 46 additions & 18 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ Total 125
2222
2323
| Field | Value |
2424
|------|------|
25-
| Problem ID | 124 |
26-
| Title | Binary Tree Maximum Path Sum |
25+
| Problem ID | 235 |
26+
| Title | Lowest Common Ancestor Of A Binary Search Tree |
2727
| Language | Python3 |
28-
| Runtime | 4 ms |
29-
| Memory | 23.9 MB |
28+
| Runtime | 66 ms |
29+
| Memory | 22.8 MB |
3030
3131
3232
💻 Languages Used
3333
34-
- **Python3** : 23
34+
- **Python3** : 24
3535
3636
## 📚 Recent Accepted Problems
3737
38+
- 235 Lowest Common Ancestor Of A Binary Search Tree
3839
- 124 Binary Tree Maximum Path Sum
3940
- 789 Kth Largest Element In A Stream
4041
- 1127 Last Stone Weight
4142
- 1014 K Closest Points To Origin
42-
- 295 Find Median From Data Stream
4343
4444
4545
---
@@ -81,4 +81,4 @@ Git
8181
GitHub
8282
⏰ Last Sync
8383
84-
2026-07-06 19:56:23
84+
2026-07-06 19:56:24
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"submission_id": "2046953410",
3+
"question_id": "235",
4+
"title_slug": "lowest-common-ancestor-of-a-binary-search-tree",
5+
"language": "python3",
6+
"language_verbose": "Python3",
7+
"runtime": "66 ms",
8+
"memory": "22.8 MB",
9+
"status_code": 10,
10+
"timestamp": 1782487150
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
10+
11+
if p.val < root.val and q.val< root.val:
12+
return self.lowestCommonAncestor(root.left, p, q)
13+
elif p.val > root.val and q.val> root.val:
14+
return self.lowestCommonAncestor(root.right, p, q)
15+
else:
16+
return root
17+

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": "2050276621"
2+
"last_submission_id": "2048068140"
33
}

storage/stats.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"medium": 56,
55
"hard": 6,
66
"languages": {
7-
"Python3": 23
7+
"Python3": 24
88
},
99
"recent_problems": [
10+
{
11+
"id": "235",
12+
"title": "Lowest Common Ancestor Of A Binary Search Tree"
13+
},
1014
{
1115
"id": "124",
1216
"title": "Binary Tree Maximum Path Sum"
@@ -22,18 +26,14 @@
2226
{
2327
"id": "1014",
2428
"title": "K Closest Points To Origin"
25-
},
26-
{
27-
"id": "295",
28-
"title": "Find Median From Data Stream"
2929
}
3030
],
3131
"last_problem": {
32-
"id": "124",
33-
"title": "Binary Tree Maximum Path Sum",
32+
"id": "235",
33+
"title": "Lowest Common Ancestor Of A Binary Search Tree",
3434
"language": "Python3",
35-
"runtime": "4 ms",
36-
"memory": "23.9 MB"
35+
"runtime": "66 ms",
36+
"memory": "22.8 MB"
3737
},
38-
"last_sync": "2026-07-06 19:56:23"
38+
"last_sync": "2026-07-06 19:56:24"
3939
}

0 commit comments

Comments
 (0)