private TreeNode helper(int[] preorder, int[] inorder) {

    if (preorder.length == 0 || inorder.length == 0) {
      return null;
    }

    TreeNode root = new TreeNode(preorder[++preIdx]);
    // if (preIdx == preorder.length - 1) {
    // preIdx = -1;
    // }

    int i = 0;
    for ( ; i < inorder.length ; i++) {
      if (inorder[i] == root.val) {
        break;
      }
    }
    root.left = helper(preorder, Arrays.copyOfRange(inorder, 0, i));
    root.right = helper(preorder, Arrays.copyOfRange(inorder, i + 1, inorder.length));

    return root;
  }