235. Lowest Common Ancestor of a Binary Search Tree
来源:互联网 发布:位面淘宝txt 编辑:程序博客网 时间:2024/06/01 23:00
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(!root) return NULL; if(root->val>max(p->val,q->val)) return lowestCommonAncestor(root->left,p,q); else if(root->val<min(p->val,q->val)) return lowestCommonAncestor(root->right,p,q); else return root; }
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(!root) return NULL; while(true){ if(root->val>max(p->val,q->val)) root=root->left; else if(root->val<min(p->val,q->val)) root=root->right; else break; } 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
- 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
- 【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree
- 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
- 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]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
- spring jdbc 使用
- ATPCS 和 AAPCS
- 条款08:别让异常逃离析构函数
- 从开博到现在的情况
- 数据结构课程设计
- 235. Lowest Common Ancestor of a Binary Search Tree
- oracle中去掉回车换行空格的方法详解
- @Configuration的使用
- php限制id为汉字
- jquery2.2.3的serialize方法如果产生错误的处理方法
- 电商独立购物车
- python学习—Day48—celery多实例与定时任务
- AOP的底层实现-CGLIB动态代理和JDK动态代理
- XrecyclerView加载数据+切换不同布局