Skip to content

Commit 61945af

Browse files
refactor 108
1 parent 7e42238 commit 61945af

File tree

1 file changed

+14
-15
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+14
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
*/
1010
public class _108 {
1111

12-
public static class Solution1 {
13-
public TreeNode sortedArrayToBST(int[] num) {
14-
return rec(num, 0, num.length - 1);
15-
}
16-
17-
public TreeNode rec(int[] num, int low, int high) {
18-
if (low > high) {
19-
return null;
20-
}
21-
int mid = low + (high - low) / 2;
22-
TreeNode root = new TreeNode(num[mid]);
23-
root.left = rec(num, low, mid - 1);
24-
root.right = rec(num, mid + 1, high);
25-
return root;
26-
}
12+
public static class Solution1 {
13+
public TreeNode sortedArrayToBST(int[] num) {
14+
return rec(num, 0, num.length - 1);
2715
}
2816

17+
public TreeNode rec(int[] num, int low, int high) {
18+
if (low > high) {
19+
return null;
20+
}
21+
int mid = low + (high - low) / 2;
22+
TreeNode root = new TreeNode(num[mid]);
23+
root.left = rec(num, low, mid - 1);
24+
root.right = rec(num, mid + 1, high);
25+
return root;
26+
}
27+
}
2928
}

0 commit comments

Comments
 (0)