标签:pre roo tree node common 二叉树 efi __init__ nbsp binary
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def lowestCommonAncestor(self, root, p, q): """ :type root: TreeNode :type p: TreeNode :type q: TreeNode :rtype: TreeNode """ if root == None or root == q or root ==p: return root left = self.lowestCommonAncestor(root.left, p, q) right = self.lowestCommonAncestor(root.right, p, q) if left and right: return root return right or left
标签:pre roo tree node common 二叉树 efi __init__ nbsp binary
原文地址:https://www.cnblogs.com/xiao-xue-di/p/10286526.html