leetcode_235
作者:互联网
package 力扣;
/**
* @program: LeetCode
* @ClassName leetcode_235
* @description:
* @author: crh
* @create: 2021-03-07 17:44
* @Version 1.0
**/
public class leetcode_235 {
//使用后序遍历进行计算
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if (root != null) {
return null;
}
return null;
}
public TreeNode lowestCommonAncestor1(TreeNode root, TreeNode p, TreeNode q) {
if (p.val == root.val) {
return p;
}
if (q.val == root.val) {
return q;
}
if (p.val > root.val && q.val > root.val) {
return lowestCommonAncestor(root.right, p, q);
} else if (p.val < root.val && q.val < root.val) {
return lowestCommonAncestor(root.left, p, q);
} else {
return root;
}
}
}
标签:TreeNode,val,return,235,null,root,leetcode 来源: https://blog.csdn.net/crh170/article/details/115140072