【2021秋冬】【剑指offer】68 – II. 二叉树的最近公共祖先
自己想不出来 只能说学习一下寻找最近公共祖先的写法了
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(root == null || p == root || q == root) return root;
TreeNode left = lowestCommonAncestor(r
共有 0 条评论