src/main/java/com/leetcode/tree/medium/SerializeAndDeserializeBST_449.java
public TreeNode deserialize(String data) {
    String[] nodes = data.split(",");
    TreeNode result = treeNodeOf(nodes[0]);

    if (result == null) {
      return null;
    }

    int curr = 1;
    Queue<TreeNode> queue = new LinkedList<>();
    queue.add(result);

    while (!queue.isEmpty()) {
      TreeNode parent = queue.remove();
      parent.left = treeNodeOf(nodes[curr++]);
      parent.right = treeNodeOf(nodes[curr++]);

      if (parent.left != null) {
        queue.add(parent.left);
      }
      if (parent.right != null) {
        queue.add(parent.right);
      }
    }

    return result;
  }
// Decodes your encoded data to tree.
Decodes your encoded data to tree.
Decodes your encoded data to tree .
public TreeNode deserialize(String data) {
    String[] nodes = data.split(",");
    TreeNode result = treeNodeOf(nodes[0]);
    if (result == null) {
      return null;
    }
    int curr = 1;
    Queue<TreeNode> queue = new LinkedList<>();
    queue.add(result);
    while (!queue.isEmpty()) {
      TreeNode parent = queue.remove();
      parent.left = treeNodeOf(nodes[curr++]);
      parent.right = treeNodeOf(nodes[curr++]);
      if (parent.left != null) {
        queue.add(parent.left);
      }
      if (parent.right != null) {
        queue.add(parent.right);
      }
    }
    return result;
  }
public TreeNode deserialize ( String data ) { String [ ] nodes = data . split ( "," ) ; TreeNode result = treeNodeOf ( nodes [ 0 ] ) ; if ( result == null ) { return null ; } int curr = 1 ; Queue < TreeNode > queue = new LinkedList < > ( ) ; queue . add ( result ) ; while ( ! queue . isEmpty ( ) ) { TreeNode parent = queue . remove ( ) ; parent . left = treeNodeOf ( nodes [ curr ++ ] ) ; parent . right = treeNodeOf ( nodes [ curr ++ ] ) ; if ( parent . left != null ) { queue . add ( parent . left ) ; } if ( parent . right != null ) { queue . add ( parent . right ) ; } } return result ; }
Decodes your encoded data to tree.
Decodes your encoded data to tree .