标签:== info 递归 www 左右 targe log src 后序
/**
* 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(root.left, p, q);
TreeNode right = lowestCommonAncestor(root.right, p, q);
if(left == null && right == null)
return null;
if(left == null)
return right;
if(right == null)
return left;
return root;
}
}
标签:== info 递归 www 左右 targe log src 后序
原文地址:https://www.cnblogs.com/GarrettWale/p/14526870.html