File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,18 @@ For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6.
24
24
*/
25
25
public class _235 {
26
26
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 ;
34
31
}
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 ;
36
39
}
37
- return root ;
38
40
}
39
41
}
You can’t perform that action at this time.
0 commit comments