Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ad97617

Browse files
refactor 108
1 parent 2e663c5 commit ad97617

File tree

1 file changed

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

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@
1414
* One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:
1515
*
1616
* 0
17-
* / \
18-
* -3 9
19-
* / /
20-
* -10 5
17+
* / \
18+
* -3 9
19+
* / /
20+
* -10 5
2121
*/
2222
public class _108 {
2323

24-
public static class Solution1 {
25-
public TreeNode sortedArrayToBST(int[] num) {
26-
return dfs(num, 0, num.length - 1);
27-
}
24+
public static class Solution1 {
25+
public TreeNode sortedArrayToBST(int[] num) {
26+
return dfs(num, 0, num.length - 1);
27+
}
2828

29-
public TreeNode dfs(int[] num, int start, int end) {
30-
if (start > end) {
31-
return null;
32-
}
33-
int mid = (end + start) / 2;
34-
TreeNode root = new TreeNode(num[mid]);
35-
root.left = dfs(num, start, mid - 1);
36-
root.right = dfs(num, mid + 1, end);
37-
return root;
29+
public TreeNode dfs(int[] num, int start, int end) {
30+
if (start > end) {
31+
return null;
32+
}
33+
int mid = (end + start) / 2;
34+
TreeNode root = new TreeNode(num[mid]);
35+
root.left = dfs(num, start, mid - 1);
36+
root.right = dfs(num, mid + 1, end);
37+
return root;
38+
}
3839
}
39-
}
4040
}

0 commit comments

Comments
 (0)