src/main/java/com/leetcode/tree/hard/SerializeAndDeserializeBinaryTree_297.java
public TreeNode deserialize(String data) {
      String[] nodes = data.split(",");
      int currIndex = 1;
      TreeNode result = nodeFromString(nodes[0]);

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

      while (currIndex < nodes.length) {
        TreeNode root = queue.remove();
        if (root == null) {
          continue;
        }
        root.left = nodeFromString(nodes[currIndex++]);
        root.right = nodeFromString(nodes[currIndex++]);
        queue.add(root.left);
        queue.add(root.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(",");
      int currIndex = 1;
      TreeNode result = nodeFromString(nodes[0]);
      Queue<TreeNode> queue = new LinkedList<>();
      queue.add(result);
      while (currIndex < nodes.length) {
        TreeNode root = queue.remove();
        if (root == null) {
          continue;
        }
        root.left = nodeFromString(nodes[currIndex++]);
        root.right = nodeFromString(nodes[currIndex++]);
        queue.add(root.left);
        queue.add(root.right);
      }
      return result;
    }
public TreeNode deserialize ( String data ) { String [ ] nodes = data . split ( "," ) ; int currIndex = 1 ; TreeNode result = nodeFromString ( nodes [ 0 ] ) ; Queue < TreeNode > queue = new LinkedList < > ( ) ; queue . add ( result ) ; while ( currIndex < nodes . length ) { TreeNode root = queue . remove ( ) ; if ( root == null ) { continue ; } root . left = nodeFromString ( nodes [ currIndex ++ ] ) ; root . right = nodeFromString ( nodes [ currIndex ++ ] ) ; queue . add ( root . left ) ; queue . add ( root . right ) ; } return result ; }
Decodes your encoded data to tree.
Decodes your encoded data to tree .