Merge pull request #113 from Joshua-Lu/patch-17
更新 0236.二叉树的最近公共祖先 Java版本
This commit is contained in:
commit
84927b1106
|
|
@ -223,12 +223,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
|
||||||
```Java
|
```Java
|
||||||
class Solution {
|
class Solution {
|
||||||
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
|
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
|
||||||
return lowestCommonAncestor1(root, p, q);
|
return lowestCommonAncestor1(root, p, q);
|
||||||
|
|
||||||
}
|
}
|
||||||
public TreeNode lowestCommonAncestor1(TreeNode root, TreeNode p, TreeNode q) {
|
public TreeNode lowestCommonAncestor1(TreeNode root, TreeNode p, TreeNode q) {
|
||||||
if (root == null || root == p || root == q) {
|
if (root == null || root == p || root == q) {
|
||||||
|
|
@ -247,6 +245,7 @@ class Solution {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// 代码精简版
|
// 代码精简版
|
||||||
class Solution {
|
class Solution {
|
||||||
|
|
@ -261,6 +260,7 @@ class Solution {
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue