public TreeNode buildTree1(int[] preorder, int[] inorder) {
        if(preorder.length == 0 || inorder.length == 0) return null; 
        TreeNode mid =  new TreeNode(preorder[0]);
        
        if(preorder.length == 1) return mid;
        
        int midIndex = -1;
        for(int i=0; i< inorder.length; i++)
        {
        	if(inorder[i] == mid.val)
        	{
        		midIndex = i; 
        		break;
        	}
        }
        
        int[] leftInorder = {}, leftPreorder= {}; 
        if(midIndex>0) 
        {
        	leftInorder = Arrays.copyOfRange(inorder, 0, midIndex);
        	leftPreorder = Arrays.copyOfRange(preorder, 1, midIndex+1);
        }
        int[] rightInorder= {}, rightPreorder= {};
        if(midIndex<inorder.length-1) 
        {
        	rightInorder = Arrays.copyOfRange(inorder, midIndex+1, inorder.length);
        	rightPreorder = Arrays.copyOfRange(preorder, midIndex+1 , preorder.length);
        }

        mid.left = buildTree1(leftPreorder, leftInorder);
        mid.right = buildTree1(rightPreorder, rightInorder);
        
        return mid; 
    }