Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33e668e

Browse files
add 1650
1 parentef94e1b commit33e668e

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ _If you like this project, please leave me a star._ ★
138138
|1657|[Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1657.java)|[:tv:](https://youtu.be/-jXQK-UeChU)|Medium|Greedy|
139139
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java)||Easy|Array, Design|
140140
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java)||Easy|Array|
141+
|1650|[Lowest Common Ancestor of a Binary Tree III](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1650.java)||Medium|HashTable, Binary Tree, Tree|
141142
|1646|[Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1646.java)||Easy|Array|
142143
|1644|[Lowest Common Ancestor of a Binary Tree II](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1644.java)||Medium|Binary Tree, DFS|
143144
|1642|[Furthest Building You Can Reach](https://leetcode.com/problems/furthest-building-you-can-reach/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1642.java)||Medium|Binary Search, Heap|
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_1650 {
7+
classNode {
8+
publicintval;
9+
publicNodeparent;
10+
publicNodeleft;
11+
publicNoderight;
12+
13+
publicNode(intval) {
14+
this.val =val;
15+
}
16+
}
17+
18+
publicstaticclassSolution1 {
19+
publicNodelowestCommonAncestor(Nodep,Nodeq) {
20+
Nodea =p,b =q;
21+
while (a !=b) {
22+
a =a ==null ?p :a.parent;
23+
b =b ==null ?q :b.parent;
24+
}
25+
returna;
26+
}
27+
}
28+
29+
publicstaticclassSolution2 {
30+
publicNodelowestCommonAncestor(Nodep,Nodeq) {
31+
Set<Node>set =newHashSet<>();
32+
while (p !=null) {
33+
set.add(p);
34+
p =p.parent;
35+
}
36+
while (q !=null) {
37+
if (set.contains(q)) {
38+
returnq;
39+
}
40+
q =q.parent;
41+
}
42+
returnnull;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp