package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

/**
 * 108. Convert Sorted Array to Binary Search Tree
 *
 * Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
 */
public class _108 {

    public static class Solution1 {
        public TreeNode sortedArrayToBST(int[] num) {
            return rec(num, 0, num.length - 1);
        }

        public TreeNode rec(int[] num, int low, int high) {
            if (low > high) {
                return null;
            }
            int mid = low + (high - low) / 2;
            TreeNode root = new TreeNode(num[mid]);
            root.left = rec(num, low, mid - 1);
            root.right = rec(num, mid + 1, high);
            return root;
        }
    }

}

@@ -262,18 +262,16 @@
 _108 %7B%0A%0A
-  
   public
@@ -296,20 +296,16 @@
 tion1 %7B%0A
-    
     publ
@@ -348,30 +348,24 @@
 um) %7B%0A      
-    
-  
 return rec(n
@@ -396,19 +396,11 @@
     
-    %7D%0A%0A    
+%7D%0A%0A
     
@@ -447,30 +447,24 @@
 int high) %7B%0A
-      
       if (lo
@@ -479,32 +479,24 @@
 ) %7B%0A        
-    
-    
 return null;
@@ -500,22 +500,16 @@
 ll;%0A
-      
       %7D%0A
     
@@ -504,22 +504,16 @@
       %7D%0A
-      
       in
@@ -550,22 +550,16 @@
 ;%0A      
-    
-  
 TreeNode
@@ -590,22 +590,16 @@
 %5Bmid%5D);%0A
-      
       ro
@@ -638,22 +638,16 @@
 ;%0A      
-  
-    
 root.rig
@@ -676,22 +676,16 @@
  high);%0A
-      
       re
@@ -699,23 +699,16 @@
 ot;%0A
-        %7D%0A
     %7D%0A
+  %7D
 %0A%7D%0A

refactor 108