tree problem (1) 썸네일형 리스트형 [LeetCode] 236. Lowest Common Ancestor of a Binary Tree https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ 불러오는 중입니다... 1. Problem 이진트리가 주어졌을 때, 두 개의 주어진 노드 p, q의 가장 작은 공통 조상 노드를 찾아라. Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 2. Algorithm 나는 p, q의 공통 조상 노드라는 것은 해당 노드를 root로 하고 탐색을 하면, p, q를 모두 찾을 수 있다는 것을 뜻한다고 생각했다. 이것은 즉 트리에서 해당 노드를 기준으로 자손 노드 중에 p, q가 존재한다는 의미. 따라서 root부터 dfs로 모든 .. 이전 1 다음