// Path: src/commons/datastructures/TreeNode.java
// public class TreeNode {
//     public int val;
//     public TreeNode left;
//     public TreeNode right;
//     public TreeNode(int x) {
//         val = x;
//     }
// 
//     @Override
//     public String toString() {
//         return "TreeNode{" +
//                 "val=" + val +
//                 '}';
//     }
// }


import commons.datastructures.TreeNode;
package ConvertSortedArraytoBinarySearchTree;


/**
 * User: Danyang
 * Date: 1/27/2015
 * Time: 16:46
 *
 * Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
 */
public class Solution {
    public TreeNode sortedArrayToBST(int[] num) {
        return toBST(num, 0, num.length);
    }

    TreeNode toBST(int[] num, int s, int e) {
// Path: src/commons/datastructures/TreeNode.java
// public class TreeNode {
//     public int val;
//     public TreeNode left;
//     public TreeNode right;
//     public TreeNode(int x) {
//         val = x;
//     }
// 
//     @Override
//     public String toString() {
//         return "TreeNode{" +
//                 "val=" + val +
//                 '}';
//     }
// }


// Path: src/ConvertSortedArraytoBinarySearchTree/Solution.java
import commons.datastructures.TreeNode;

package ConvertSortedArraytoBinarySearchTree;


/**
 * User: Danyang
 * Date: 1/27/2015
 * Time: 16:46
 *
 * Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
 */
public class Solution {
    public TreeNode sortedArrayToBST(int[] num) {
        return toBST(num, 0, num.length);
    }

    TreeNode toBST(int[] num, int s, int e) {
        if(s>=e)