2351 235, Lowest Common Ancestor of a Binary Search Tree # 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: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': """가장 작은 부모 찾기 경우의 수: * P, Q가 부모 노드 왼쪽에만 존재하는 경우 * P, Q가 부모 노드 오른쪽에만 존재하는 경우 * P는 부모 노드 왼쪽, Q는 부모 노드 오른쪽에 존재하는 경우 * P 또는 Q 중 하나가 루트 노드에 존재하는 경우 LCA, Lowes.. 2024. 2. 25. 이전 1 다음