Skip to content

Commit a08a9fd

Browse files
refactor 235
1 parent 416442a commit a08a9fd

File tree

1 file changed

+11
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+11
-9
lines changed

src/main/java/com/fishercoder/solutions/_235.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6.
2424
*/
2525
public class _235 {
2626

27-
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
28-
if (root == null || p == root || q == root) {
29-
return root;
30-
}
31-
if ((root.val - p.val) * (root.val - q.val) > 0) {
32-
if (root.val - p.val > 0) {
33-
return lowestCommonAncestor(root.left, p, q);
27+
public static class Solution1 {
28+
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
29+
if (root == null || p == root || q == root) {
30+
return root;
3431
}
35-
return lowestCommonAncestor(root.right, p, q);
32+
if ((root.val - p.val) * (root.val - q.val) > 0) {
33+
if (root.val - p.val > 0) {
34+
return lowestCommonAncestor(root.left, p, q);
35+
}
36+
return lowestCommonAncestor(root.right, p, q);
37+
}
38+
return root;
3639
}
37-
return root;
3840
}
3941
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy