public BinaryNode<Integer> deserialize(String tree) {
    validateInput(tree);

    if (index >= tree.length()) {
      return null;
    } else {
      char currentChar = tree.charAt(index);
      if (currentChar == '#') {
        index++;
        return null;
      } else {
        BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48);
        index++;
        node.setLeft(deserialize(tree));
        node.setRight(deserialize(tree));
        return node;
      }
    }
  }
Recursive algorithm based a static index to recreate the original tree properly. The
complexity order of this algorithm is O(N) where N is the number of chars in the input String.
src/main/java/com/github/pedrovgs/problem46/BinaryTreeSerialization.java