LeetCode Lowest Common Ancestor of a Binary Search Tree
来源:互联网 发布:高速公路机电系统优化 编辑:程序博客网 时间:2024/06/17 07:58
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) { if(root==NULL) return NULL; else if(root->val<p->val&&root->val<q->val) return lowestCommonAncestor(root->right,p,q); else if(root->val>p->val&&root->val>q->val) return lowestCommonAncestor(root->left,p,q); else return root;}
这个题是找两节点最近祖先节点,开始理解成找最近最小祖先节点打算用数组记录。
后发现题目含义之后,改用递归方法。
C语言 2016/2/13
0 0
- leetcode 235: Lowest Common Ancestor of a Binary Search Tree
- LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
- leetcode: Lowest Common Ancestor of a Binary Search Tree
- [leetcode][dfs] 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] Lowest Common Ancestor of a Binary Search Tree
- LeetCode Lowest Common Ancestor of a Binary Search Tree
- leetCode(38):Lowest Common Ancestor of a Binary Search Tree
- leetcode-235-Lowest Common Ancestor of a Binary Search Tree
- [LeetCode]Lowest Common Ancestor of a Binary Search Tree
- Leetcode: Lowest Common Ancestor of a Binary Search Tree
- leetcode[235]:Lowest Common Ancestor of a Binary Search Tree
- Lowest Common Ancestor of a Binary Search Tree-leetcode
- 【leetcode】Lowest Common Ancestor of a Binary Search Tree
- 【Leetcode】Lowest Common Ancestor of a Binary Search Tree
- LVS的DR模式
- 多重背包转01背包/母函数(1171)
- 使用spring web flow遇到的问题-1
- UEFI模式下安装ubuntu14.04和windows8.1双系统
- iOS-网络七层模型&&网络数据包
- LeetCode Lowest Common Ancestor of a Binary Search Tree
- 为什么直接执行shell脚本可以,但crontab下执行错误
- ViewPager中requestDisallowInterceptTouchEvent
- Android中Activity四种启动模式和taskAffinity属性详解
- 新的一年,要开始写博客了!
- 华为机试题:Arrange an Array to Form a Smallest Digit
- Linux--ubuntu 14.04 install g++问题
- dx11学习笔记-3.三维空间变换(自己整理,基础详尽)
- hdu3247Resource Archiver (AC自动机+最短路+状压dp)