Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43f30b2

Browse files
committed
修复 0235.二叉搜索树的最近公共祖先.md Python3解法
1 parent c41ce18 commit 43f30b2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎problems/0235.二叉搜索树的最近公共祖先.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,15 @@ class Solution {
260260
递归法:
261261
```python
262262
class Solution:
263+
"""二叉搜索树的最近公共祖先 递归法"""
264+
263265
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
264-
if notroot: returnroot//
265-
if root.val >p.val androot.val > q.val:
266-
returnself.lowestCommonAncestor(root.left,p,q) //
267-
elif root.val < p.val androot.val < q.val:
268-
return self.lowestCommonAncestor(root.right,p,q) //
269-
else: return root
266+
if root.val > p.val androot.val > q.val:
267+
returnself.lowestCommonAncestor(root.left, p, q)
268+
if root.val < p.val androot.val < q.val:
269+
returnself.lowestCommonAncestor(root.right, p, q)
270+
return root
271+
270272
```
271273

272274
迭代法:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /