mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #113 from Joshua-Lu/patch-17
更新 0236.二叉树的最近公共祖先 Java版本
This commit is contained in:
@ -223,12 +223,10 @@ public:
|
||||
|
||||
|
||||
Java:
|
||||
|
||||
```Java
|
||||
class Solution {
|
||||
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
|
||||
return lowestCommonAncestor1(root, p, q);
|
||||
|
||||
}
|
||||
public TreeNode lowestCommonAncestor1(TreeNode root, TreeNode p, TreeNode q) {
|
||||
if (root == null || root == p || root == q) {
|
||||
@ -247,6 +245,7 @@ class Solution {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```java
|
||||
// 代码精简版
|
||||
class Solution {
|
||||
@ -261,6 +260,7 @@ class Solution {
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Python:
|
||||
|
||||
|
Reference in New Issue
Block a user