【Leetcode 236】Lowest Common Ancestor of a Binary Tree
难度: 中等(Medium)
题目
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
思路
分别求出跟节点到p,q的路径,那么路径的共同前缀的末尾即为所求。
代码
1 | # Definition for a binary tree node. |
难度: 中等(Medium)
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
分别求出跟节点到p,q的路径,那么路径的共同前缀的末尾即为所求。
1 | # Definition for a binary tree node. |
评论系统未开启,无法评论!