File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -23,17 +23,17 @@ public class _108 {
23
23
24
24
public static class Solution1 {
25
25
public TreeNode sortedArrayToBST (int [] num ) {
26
- return rec (num , 0 , num .length - 1 );
26
+ return dfs (num , 0 , num .length - 1 );
27
27
}
28
28
29
- public TreeNode rec (int [] num , int low , int high ) {
30
- if (low > high ) {
29
+ public TreeNode dfs (int [] num , int start , int end ) {
30
+ if (start > end ) {
31
31
return null ;
32
32
}
33
- int mid = low + (high - low ) / 2 ;
33
+ int mid = start + (end - start ) / 2 ;
34
34
TreeNode root = new TreeNode (num [mid ]);
35
- root .left = rec (num , low , mid - 1 );
36
- root .right = rec (num , mid + 1 , high );
35
+ root .left = dfs (num , start , mid - 1 );
36
+ root .right = dfs (num , mid + 1 , end );
37
37
return root ;
38
38
}
39
39
}
You can’t perform that action at this time.
0 commit comments