【Leetcode】235. Lowest Common Ancestor of a Binary Search Tree 解題報告

求二叉排序中的最近公共祖先 方法1 遞歸法 找到一個節點的值大於左變小於右邊即可 class Solution1(object): def lowestCommonAncestor(self, root, p, q): p = p.val q = q.val if q < p: q,p = p,q re
相關文章
相關標籤/搜索