leetcode 236 Lowest Common Ancestor of a Binary Tree
来源:互联网 发布:减肥不减胸 知乎 编辑:程序博客网 时间:2024/05/21 17:13
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(!root||root==p||root==q) { return root; } TreeNode* left=lowestCommonAncestor(root->left,p,q); TreeNode* right=lowestCommonAncestor(root->right,p,q); if(left&&right) { return root; } else { return left==NULL?right:left; } }};
阅读全文
0 0
- 【LeetCode】236 Lowest Common Ancestor of a Binary Tree
- leetcode 236: Lowest Common Ancestor of a Binary Tree
- Leetcode 236 Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- [Leetcode 236, Medium] Lowest Common Ancestor of a Binary Tree
- leetcode[236]:Lowest Common Ancestor of a Binary Tree
- Leetcode NO.236 Lowest Common Ancestor of a Binary Tree
- Leetcode #236 Lowest Common Ancestor of a Binary Tree
- [leetcode 236]Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- [LeetCode 236] Lowest Common Ancestor of a Binary Tree
- LeetCode(236)Lowest Common Ancestor of a Binary Tree
- leetcode 236: Lowest Common Ancestor of a Binary Tree
- LeetCode 236: Lowest Common Ancestor of a Binary Tree
- 【LEETCODE】236-Lowest Common Ancestor of a Binary Tree
- LeetCode 236 Lowest Common Ancestor of a Binary Tree
- 【LeetCode-236】Lowest Common Ancestor of a Binary Tree
- leetcode 236Lowest Common Ancestor of a Binary Tree [python]
- 九度OJ
- 2017暑假实习
- 性能分析工具vtune使用
- Symmetric Difference
- Android之ToolBar使用
- leetcode 236 Lowest Common Ancestor of a Binary Tree
- 区间DP
- java基础知识简化
- 房卡麻将开发之”代开房间”
- 项目经理(一)
- redis集群搭建
- 查找数组里的指定元素
- 前端面试篇2017-6-26
- fastjson 转换long型报错