235. Lowest Common Ancestor of a Binary Search Tree

Posted gopanama

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了235. Lowest Common Ancestor of a Binary Search Tree相关的知识,希望对你有一定的参考价值。

身体不好

 

 1 class Solution {
 2     public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
 3         if(p.val < root.val && q.val < root.val) {
 4             return lowestCommonAncestor(root.left, p , q);
 5         }else if(p.val > root.val && q.val > root.val) {
 6             return lowestCommonAncestor(root.right, p , q);
 7         }else {
 8             return root;
 9         }   
10     } 
11 }

 

以上是关于235. Lowest Common Ancestor of a Binary Search Tree的主要内容,如果未能解决你的问题,请参考以下文章

LC.235.Lowest Common Ancestor of a Binary Search Tree

LeetCode 236. Lowest Common Ancestor of a Binary Tree; 235. Lowest Common Ancestor of a Binary Searc

#Leetcode# 235. Lowest Common Ancestor of a Binary Search Tree

235. Lowest Common Ancestor of a Binary Search Tree

235. Lowest Common Ancestor of a Binary Search Tree

235. Lowest Common Ancestor of a Binary Search Tree