leetcode题235. Lowest Common Ancestor of a Binary Search Tree
来源:互联网 发布:星球模拟软件 编辑:程序博客网 时间:2024/06/05 05:12
class Solution {public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { //对于二叉搜索树,根节点一定小于较小的值而大于较大的值 //因此如果两个节点大于根节点,则两个节点在右边;如果两个节点小于根节点,则两个节点在左边, //否则在两边,最小公共节点即为根节点 if(p->val > root->val && q->val > root->val) return lowestCommonAncestor(root->right,p,q); if(p->val < root->val && q->val < root->val) return lowestCommonAncestor(root->left,p,q); return root; }};
0 0
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- [leetcode] 235.Lowest Common Ancestor of a Binary Search Tree
- [LeetCode]235.Lowest Common Ancestor of a Binary Search Tree
- 【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree
- 235. Lowest Common Ancestor of a Binary Search Tree LeetCode
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- [LeetCode]235. Lowest Common Ancestor of a Binary Search Tree
- [LeetCode]235. Lowest Common Ancestor of a Binary Search Tree
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- [leetcode] 235. Lowest Common Ancestor of a Binary Search Tree
- 【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree
- leetcode:235. Lowest Common Ancestor of a Binary Search Tree
- LeetCode *** 235. Lowest Common Ancestor of a Binary Search Tree
- LeetCode-235.Lowest Common Ancestor of a Binary Search Tree
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- leetcode-235. Lowest Common Ancestor of a Binary Search Tree
- 235.[Leetcode]Lowest Common Ancestor of a Binary Search Tree
- 【leetcode】235. Lowest Common Ancestor of a Binary Search Tree
- Digitalocean VPS centos 7安装图形化界面KDE和VNC实现远程图形化操作
- POJ3624--Charm Bracelet(dp)
- DP新姿势
- sleep 和 wait 区别
- 希尔排序(java实现)
- leetcode题235. Lowest Common Ancestor of a Binary Search Tree
- C语言拓展笔记
- 思维导图系列(1)-那些年IM的一些总结
- 哈希表
- 图像预处理——边界跟踪、图像分割
- iOS支付宝支付(Alipay)详细接入
- 1
- 2
- eagle使用注意点